Jump to content
Girish Dubey

Jquery migrate jquery-1.8.1.min.js to jquery-3.1.1.min.js (.live replace with .on)

Recommended Posts

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 by Girish Dubey

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×