-1
<div id="address" class="col s12">
            <div class="row">
              <form method="post" action="" id="addressDetails">
                <div class="input-field col s6">
                  <textarea id="lAddress" name = 'lAddress' minlength='20' maxlength='100' class="materialize-textarea" class="validate" required length="100"></textarea>
                  <label for="lAddress" data-error="Must be between 20 to 100 Characters">Local Address</label>
                </div>
                <div class="input-field col s6">
                  <textarea id="pAddress" name = 'pAddress' minlength='20' maxlength='100' class="materialize-textarea" class="validate" required length="100"></textarea>
                  <label for="pAddress" data-error="Must be between 20 to 100 Characters">Permanent Address</label>
                </div>
              </form>
            </div>
            <div class="row center-align">
              <button type="submit" name="submitAddress" form="addressDetails" class="waves-effect waves-light light-blue darken-1 btn updateProfile">Save Address Details</button>
            </div>
          </div>

HTML and JavaScript Code

$(document).ready(function() {
    $("button").on('click', '.updateProfile', function(event) {
        event.preventDefault();
    });
});

This is my javascript. I simplified it keep it short. My event.preventDefault() is not working.

Rahul Kumar
  • 2,184
  • 3
  • 24
  • 46

2 Answers2

1

You have binded your click handler in incorrect way.

Try this code instead:

$(".updateProfile").on('click', function(event) {
    event.preventDefault();
});
nicael
  • 18,550
  • 13
  • 57
  • 90
Mohit Bhardwaj
  • 9,650
  • 3
  • 37
  • 64
1

Based on your HTML markup <button> element already has class updateProfile, so your code should look like that:

$('button.updateProfile').on('click', function(e) {
    e.preventDefault();
});

In your case passing .updateProfile as a second argument of on method binds click event to the element with class updateProfile inside <button> element in a delegated way.

VisioN
  • 143,310
  • 32
  • 282
  • 281