Running the following code, I expect to see the relative forms, so I can extract information from them. Instead, this points to the document.
I assume it is related to using a live binding, is there a work around?
$('.form_one').add('.form_two').live('submit',function(e){
e.preventDefault();
console.log($(this));
})
This is because
live()is a shortcut for delegating an event handler to the highest level DOM element –document– which is why the scope ofthispoints there.As a workaround you should use
$(e.target)to get the element which raised the event.Also,
live()has been deprecated, you should be usingdelegate()oron()if you are using jQuery 1.7+.Example fiddle