$('.kkk').live('click',function() {
// Execute Event
});
$('body').append('<div class="kkk">Another target</div>');
using live
will match all future elements written to the page as well as those that exist when the event is "bound".
UPDATE:
jQuery as of 1.7 has deprecated live
(and bind
) in favour of using on
with delegated events. To use a delegated event, you attach on
to an element that will exist on the page at load, then filter by a selector that will exist later. For example:
$('body').on('click', '.kkk', function(){
// Execute Event
});
$('body').append('<div class="kkk">Another target</div>');
If the element will exist on the page when document onload
is fired, you can simply attach it as:
$('body .kkk').on('click', function(){
// Execute Event
});