Girish Dubey Posted November 17, 2016 Share Posted November 17, 2016 (edited) I am trying to bind dynamic event but i am not able to bind. previously i have used .live in our system that was working find now we are going to migrate our system to jquery 3.1.1. and i have replace all .live to .on function but work. for you reference.. <html> <head> <script src="jquery-3.1.1.min.js"></script> <!-- <script src="jquery-1.8.1.min.js"></script> --> <script> var abcHandler = function() { var h=this; h.getControl = function(cntrl) { return $("[class$='Cntrl_" + cntrl + "']"); }; h.main = h.getControl('main'); h.divid1 = h.getControl('divid1'); h.divid2 = h.getControl('divid2'); } abcHandler.prototype.BindEvents = function() { var h=this; h.main.append("<a class='Cntrl_divid1' href='#'>View Details1</a><br />"); h.main.append("<a class='Cntrl_divid2' href='#'>View Details2</a>"); h.divid1.click(function () { alert(this.innerHTML); }); h.divid2.click(function () { alert(this.innerHTML); }); }; var handler; $(document).ready(function() { handler = new abcHandler(); handler.BindEvents(); }); </script> </head> <body> <div class="Cntrl_main"> </div> </body> </html> Please suggest me how i can fix this issue. das Edited November 17, 2016 by Girish Dubey Link to comment Share on other sites More sharing options...
dsonesuk Posted November 17, 2016 Share Posted November 17, 2016 Jquery 'on' works differently to 'live', in that it is applied to the always existing parent element that will target any newly appended child elements with specific selector identifier. Link to comment Share on other sites More sharing options...
thescientist Posted November 17, 2016 Share Posted November 17, 2016 From the live docs, there is a lot of information about upgrading to on http://api.jquery.com/live/ Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now