开发者

e.preventDefault() is not working on div onclick

开发者 https://www.devze.com 2023-02-28 14:56 出处:网络
preventDefault() is not working on div onclick, i tried preventDefault and stopImmediatePropagation also nothing works, please see the below sample.

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

精彩评论

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