开发者

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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜