sfgroups
sfgroups

Reputation: 19133

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 );

                            });

Upvotes: 0

Views: 723

Answers (1)

PSL
PSL

Reputation: 123739

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 );
       });

});

Upvotes: 1

Related Questions