views:

31

answers:

2
+1  A: 

You can use .live() for what you want, like this:

$("#reservationForm").live("submit", function(f){
  f.preventDefault();
  alert("Jawel");
});

.live() event handlers work slightly different, they aren't on the elements themselves (it adds a handler to document), so it can work on future elements added to the page later by listening for their events to bubble up, events bubble the same way, regardless of when the elements were added.

Nick Craver
Wow! That works! Thanks!
Maurice
@Maurice - Welcome :)
Nick Craver
A: 

to auto bind events to dom created you can use .live();

eg:

jQuery('.red').live('click',_functionDoSomething);

now in future if you add more elements with class=red they will have function=_functionDoSomething alreday attached to them

Praveen Prasad
To be clear this doesn't "autobind", it works off event bubbling, no actual code runs when DOM elements are added, it's completely passive.
Nick Craver