javascript - Hook that applies to elements inserted later -
functions on javascript/jquery selectors apply elements on page before function read. example,
$('.foo').css('color', 'red');
applies elements class foo
@ time part of code read, not apply elements inserted later via javascript/jquery functions such append()
, etc. there way define hook applies automatically @ time when element inserted?
using $('.foo')
selector match elements foo
class whether they've been added after load or not.
for events: .live()
has been removed newer versions of jquery should use .on()
. here's example:
$(document).on('click', '.foo', function(){ // click event code here });
this event match .foo
elements when page loads loaded via .append()
, .html()
etc.
update:
i think understand mean now. there's plugin called live query should solve problem. include use:
$('.foo').livequery(function() { $(this).css('color', 'red'); });
here's working demo: http://jsfiddle.net/5jjae/
Comments
Post a Comment