stoppropagation

Why does preventDefault() on a parent element's click 'disable' a checkbox?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-29 13:47:34
问题 I encountered this situation recently (simplified here). Simply wrap a checkbox with an element and apply preventDefault() on it's click event and the checkbox becomes uncheckable. See this fiddle, but here's a snip: <div> <input type="checkbox"/> </div> /* Wrapper could be any element (and any ancestor element will work) */ $('div').on('click', function(e){ e.preventDefault(); }); /* Uncomment to make the checkbox work again $('input').on('click', function(e){ e.stopPropagation(); }); */ The

How to disable scrolling in outer elements?

*爱你&永不变心* 提交于 2019-11-29 03:31:24
I have a vertically-scrolling div within a page that also scrolls vertically. When the child div is scrolled with the mouse wheel and reaches the top or bottom of the scroll bar, the page (body) begins to scroll. While the mouse is over the child div, I'd like the page (body) scroll to be locked. This SO post (scroll down to the selected answer) demonstrates the problem well. This SO question is essentially the same as mine, but the selected answer causes my page contents to noticeably shift horizontally as the scrollbar disappears and reappears. I thought there might be a solution that

event.preventDefault vs event.stopPropagation [duplicate]

时光总嘲笑我的痴心妄想 提交于 2019-11-28 06:29:23
This question already has an answer here: What's the difference between event.stopPropagation and event.preventDefault? 7 answers Can someone explain what's the difference between event.preventDefault() and event.stopPropagation() ? I have a table and within that table I have an img tag. When I click the img tag, I want to see a popup. But I also want to stop the selection of multiple rows, so I use: $("table.items tbody tr").click(function(event) { event.stopPropagation(); }); When I use the js code, the popup does not appear; If I delete the js code, the popup works. $(".info").live("click"

jQuery on() stopPropagation not working?

↘锁芯ラ 提交于 2019-11-27 20:34:09
I can't seem to get this to stop propagating.. $(document).ready(function(){ $("body").on("click","img.theater",function(event){ event.stopPropagation(); $('.theater-wrapper').show(); }); // This shouldn't fire if I click inside of the div that's inside of the // `.theater-wrapper`, which is called `.theater-container`, anything else it should. $(".theater-wrapper").click(function(event){ $('.theater-wrapper').hide(); }); }); Refer this jsfiddle Since you are using on on the body element and not directly on img.theater the event is going to bubble up to body element and that is how it works.

How to disable scrolling in outer elements?

岁酱吖の 提交于 2019-11-27 17:36:00
问题 I have a vertically-scrolling div within a page that also scrolls vertically. When the child div is scrolled with the mouse wheel and reaches the top or bottom of the scroll bar, the page (body) begins to scroll. While the mouse is over the child div, I'd like the page (body) scroll to be locked. This SO post (scroll down to the selected answer) demonstrates the problem well. This SO question is essentially the same as mine, but the selected answer causes my page contents to noticeably shift

event.preventDefault vs event.stopPropagation [duplicate]

一曲冷凌霜 提交于 2019-11-27 01:22:17
问题 This question already has answers here : What's the difference between event.stopPropagation and event.preventDefault? (7 answers) Closed 6 years ago . Can someone explain what's the difference between event.preventDefault() and event.stopPropagation() ? I have a table and within that table I have an img tag. When I click the img tag, I want to see a popup. But I also want to stop the selection of multiple rows, so I use: $("table.items tbody tr").click(function(event) { event.stopPropagation

What&#39;s the difference between event.stopPropagation and event.preventDefault?

孤者浪人 提交于 2019-11-25 22:28:25
问题 They seem to be doing the same thing... Is one modern and one old? Or are they supported by different browsers? When I handle events myself (without framework) I just always check for both and execute both if present. (I also return false , but I have the feeling that doesn\'t work with events attached with node.addEventListener ). So why both? Should I keep checking for both? Or is there actually a difference? (I know, a lot of questions, but they\'re all sort of the same =)) 回答1: