0

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?

corroded
  • 21,406
  • 19
  • 83
  • 132
  • Though it's not a real answer to your question, a workaround would be to bind to the click event of your submit button. – András Szepesházi Mar 21 '11 at 07:50
  • i tried that but this is in relation to this problem: http://stackoverflow.com/questions/5374322/ie-problem-with-getting-ajax-html-response/5374348#5374348 – corroded Mar 21 '11 at 08:02

1 Answers1

4

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.

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143