<commit_before>---
layout: post
title:  "Why jQuery's event.preventDefault() Couldn't Stop a Link From To Redirect?"
date:   2017-07-26 19:07:56 +0000
---


For my fourth project, I needed to add dynamic features to my Rails app that is possible only through jQuery and a JSON API.

After working on Rails for a couple of months, going back to Jquery was a little bumpy journey but there was one thing that really gave me a hard time - Making work anchor tag and jQuery's event.preventDefault() with each other!


The jQuery's one of the most useful method - event.preventDefault(), it stops the default action of an element from happening.

Such as: 

* It prevents a submit button from submitting a form<commit_msg>Updating my blog post.<commit_after>---
layout: post
title:  "Why jQuery's event.preventDefault() Couldn't Stop a Link From To Redirect?"
date:   2017-07-26 15:07:57 -0400
---


For my fourth project, I needed to add dynamic features to my Rails app that is possible only through jQuery and a JSON API.

After working on Rails for a couple of months, going back to Jquery was a little bumpy journey but there was one thing that really gave me a hard time - Making work anchor tag and jQuery's event.preventDefault() with each other!


The jQuery's one of the most useful method - event.preventDefault(), it stops the default action of an element from happening.

Such as: 

* It prevents a submit button from submitting a form
{'fraction_non_alphanumeric': 0.060291060291060294, 'fraction_numerical': 0.02494802494802495, 'mean_word_length': 4.013888888888889, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1699984', 'n_tokens_mistral': 403, 'n_tokens_neox': 365, 'n_words': 226}