e.preventDefault() is not working on div onclick
preventDefault() is not working on div onclick, i tried preventDefault and stopImmediatePropagation also nothing works, please see the below sample.
<title></title>
<script src="scripts/jquery-1.5.2.min.js" type="text/javascript"></script>
开发者_如何转开发<script type="text/javascript">
$().ready(function () {
$("div").click(function (e) {
e.preventDefault();
//e.stopImmediatePropagation();
return false;
});
//$("div").bind("click", function (e) { e.stopImmediatePropagation(); return false; });
});
</script>
<div onclick="alert('1');">
Sample text
</div>
There is no default behaviour of clicking on a div. What are you trying to prevent?
Also event.stopPropagation() is to stop the event from bubbling up ancestors and triggering their event handlers. What is it triggering in your case?
加载中,请稍侯......
精彩评论