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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -