简体   繁体   中英

Passing a function to the jquery On event handler

This works:

$(".logo").click(doSomething)

This does not:

$('.popular').on '.logo', 'click', doSomething

I need the latter because some .logo elements are loaded using AJAX after the page is done loading.

What can I do to fix it?

You can write

$('.popular').on('click','.logo', function() {
// do something
 topServiceClicked();});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM