no jQuery on inserted HTML -
i have jquery loaded in head of page, on click of elements class.
$(function(){ $(".addtocal").click(function(){ $(this).next('.addtocaloptions').fadein('fast'); return false; } ); });
it works .addtocal elements present on page. not bunch of similar elements inserted in page later jquery .load function.
now i'm pretty sure have use "a delegated-events approachth" .on() function. right?
this doesn't work, though:
$(function(){ $("a").on("click", ".addtocal", function(){ $(this).next('.addtocaloptions').fadein('fast'); } ); });
i'm lost. thoughts? thanks!
you use document delegate, because delegate have static (not dynamically added):
$(function(){ $(document).on("click", ".addtocal", function(){ $(this).next('.addtocaloptions').fadein('fast'); } );
but better use closest static container instead of document.
Comments
Post a Comment