Skip to content

Instantly share code, notes, and snippets.

@marsen
Last active December 29, 2015 12:19
Show Gist options
  • Save marsen/7670155 to your computer and use it in GitHub Desktop.
Save marsen/7670155 to your computer and use it in GitHub Desktop.
.On vs .Live in JQuery,Attach an event, now and in the future. Using jquery-1.8.3.min.js
<html>
<head>
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script>
$(function(){
$('#wrapper').on('click','#onlink',function(event){
alert('on link was clicked');
});
$("#livelink").live('click',function(){
alert('live link was clicked');
});
$("#btn").click(function(){
$("#wrapper").html("<a href='#' id='livelink' >live click</a><br /><a href='#' id='onlink' >on click</a><br /><a href='#' >other click</a><br />");
});
});
</script>
</head>
<body>
On vs Live in JQuery,Attach an event, now and in the future.<br />
<input id="btn" type="button" value="text" />
<div id="wrapper">
</div>
</body>
<html>
@marsen
Copy link
Author

marsen commented Dec 5, 2013

1.9以後應以on取代live

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment