Created
August 6, 2010 19:23
-
-
Save kuinak/511840 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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