Use jQuery to unbind a click handler that wasn't added with jQuery?
I want to use jQuery to r开发者_如何学Goemove a click event handler that wasn't added with jQuery. For example:
<a onclick="alert('This was set by onclick.')" href="#">Click me</a>
<script type="text/javascript">
$(document).ready(function(){
$("a").unbind(); // Why isn't this working?
$("a").click(function(event){
alert("This was set by jquery click.");
});
});
</script>
Is this possible? $("a").unbind() isn't working. The above code displays both alert() windows and not just the one added by jQuery. I think unbind() only unbinds handlers which were bound with bind().
Try removeAttr instead:
$('a').removeAttr('onclick');
加载中,请稍侯......
精彩评论