Question

I am trying to bind the submit function to a number of forms in my page, but the problem is they still keep submitting the form!

I tried these:

$(".toggle-form-submit").parents("form").live("submit", function(e){
  var myForm = $(this);
  console.log(myForm);

  e.preventDefault();
  return false;
});

SUBMITS FORM

live("submit"...

livequery("submit"...

WORKS AS INTENDED

 submit(function()...

why doesn't it work if it is live or even livequery?

Was it helpful?

Solution

From the documentation:

DOM traversal methods are not supported for finding elements to send to .live(). Rather, the .live() method should always be called directly after a selector, as in the example above.

So you need a selector that selects those forms, using parents() won't work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top