Reputation: 1135
I have some js and jquery on page (in external file), and everything is working fine on the pageload. All the effects are working fine. The problem starts when i submit form through jquery and get more js data from the server and append it to the body through jquery. The data itself is jquery and adds HTML to a specified element. Now, anything inside that piece of HTML doesnt trigger previous jquery code. I have to resend the same code again and again with each ajax response. Is this a problem on normal behaviour of the language.
Im a beginner.
Herz the code that works fine before, but doesnt afterwords:
$('form').submit( function() {
switch( $(this).attr('name') )
{
case 'ajaxeditbookmarkform':
alert( '1' );
case 'ajaxbookmarkform':
alert( '2' );
}
return false;
});
Upvotes: 0
Views: 130
Reputation: 1162
First off. Yes this is normal behavior. What you could try to do is to use the .live function from jQuery like so:
$('form').live('submit', function() {
switch( $(this).attr('name') )
{
case 'ajaxeditbookmarkform':
alert( '1' );
case 'ajaxbookmarkform':
alert( '2' );
}
return false;
});
Upvotes: 1
Reputation: 1917
try live events.....
This method provides a means to attach delegated event handlers to the document element of a page, which simplifies the use of event handlers when content is dynamically added to a page. See the discussion of direct versus delegated events in the .on() method for more information.
Upvotes: 2