简体   繁体   中英

jquery 1.9.1 on event not working

With Jquery v1.5.2 following function works, I have upgraded jquery to 1.9.1 live has been replaced to on function. if I change live to on. its not working.

I changed on to live and included the migration plugin its working. how can I use this with on function

$( ".pop-up" ).live(
                        "click",
                            function( event ){
                                // get the id of the item clicked on
                                var id = $(this).attr('id');
                                 alert(id)
                            // block the href actually working
                            return( false );

                            });

Try this

Instead of document you could use the selector that already exists in DOM, If this element is added dynamically to the DOM at a later time.

$(function(){
      $(document).on("click", ".pop-up",
        function( event ){
                            // get the id of the item clicked on
                            var id = $(this).attr('id');
                             alert(id)
                        // block the href actually working
                        return( false );
       });

});

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