Skip to content

Instantly share code, notes, and snippets.

@kuinak
Created August 6, 2010 19:23
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 kuinak/511840 to your computer and use it in GitHub Desktop.
Save kuinak/511840 to your computer and use it in GitHub Desktop.
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script>
$(document).ready(function() {
// live/die doesn't seem get unbound from element specified by alternate selector
$(".foo").live("click", function() {
alert("foo");
return true;
});
$(".dont-do-foo").die(); // this doesn't seem to unbind the foo function
// $(".foo").die(); // this unbinds foo from the element, but that's not
// how i want it to work, because it also unbinds from
// the first link as well
$(".dont-do-foo").live("click", function(){
alert("dont-do-foo");
return false;
});
// using bind/unbind gives expected results
$(".bar").bind("click", function() {
alert("bar");
return true;
});
$(".dont-do-bar").unbind();
$(".dont-do-bar").bind("click", function(){
alert("dont-do-bar");
return false;
});
});
</script>
this should alert <a href="./test.html?foo" class="foo">foo</a> (win!)
<br/>
this should alert <a href="./test.html?dont-do-foo" class="foo dont-do-foo">don't do foo</a> (fail!)
<br>
this should alert <a href="./test.html?bar" class="bar">bar</a> (win!)
<br/>
this should alert <a href="./test.html?dont-do-bar" class="bar dont-do-bar">don't do bar</a> (win!)
<br>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment