Skip to content

Instantly share code, notes, and snippets.

@sauron
Created April 5, 2013 01:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sauron/5315848 to your computer and use it in GitHub Desktop.
Save sauron/5315848 to your computer and use it in GitHub Desktop.
Comparaciones entre live() y on()
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script>
function addClick(){
$("span.clickeable").live("click", function(){
alert("clicked");
})
};
function addSpan(){
$("body").append('<br /><span class="clickeable">Clickeable</span>')
};
$(document).ready(function() {
addClick();
});
</script>
</head>
<body>
<a href="javascript:addSpan()">Agregar otro clickeable</a>
<br />
<span class="clickeable">Clickeable</span>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
function addClick(){
$("span.clickeable").on("click", function(){
alert("clicked");
})
};
function addSpan(){
$("body").append('<br /><span class="clickeable">Clickeable</span>')
};
$(document).ready(function() {
addClick();
});
</script>
</head>
<body>
<a href="javascript:addSpan()">Agregar otro clickeable</a>
<br />
<span class="clickeable">Clickeable</span>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment