Welcome Guest, Not a member yet? Register   Sign In
jquery refresh?
#4

[eluser]slowgary[/eluser]
Sweet! I know this one. When you add an event handler like so:
Code:
$('.Fremove').click(function(){
     //do something
});

//or like this, which is how I prefer it:
$('.Fremove').bind('click', function(){
     //do something
}):
jQuery jogs through the DOM and adds an event handler to each of the matching objects. But when you add a new object after that code was executed, the new object missed the party, so it doesn't have an event handler. Fortunately for YOU, jQuery thought of that. There's a function called 'live' that works like 'bind', except that it watched for all new elements added to the DOM, and if they match the selector they TOO get the event handler. So:

Code:
$(document).ready(function(){
     $('.Fremove').live('click', function(){
          alert('sweet!');
          //no need to return false;
     });
});

Keep at it, jQuery is the best JavaScript framework and I've tried the others so I know. The documentation is great, always dig through when you come up with a problem like this and soon you'll find yourself checking it less and less. Good luck.


Messages In This Thread
jquery refresh? - by El Forum - 06-18-2009, 05:47 PM
jquery refresh? - by El Forum - 06-18-2009, 06:21 PM
jquery refresh? - by El Forum - 06-18-2009, 07:06 PM
jquery refresh? - by El Forum - 06-18-2009, 09:19 PM
jquery refresh? - by El Forum - 06-19-2009, 10:01 AM
jquery refresh? - by El Forum - 06-19-2009, 03:50 PM



Theme © iAndrew 2016 - Forum software by © MyBB