Javascript/jQuery Click Element within Element

我的梦境 提交于 2019-12-11 09:13:29

问题


This is probably something quite easy to resolve, but for some reason, I can't figure it out.

I have the following HTML:

<li onclick="function_1();">
  <input type="checkbox" onclick="function_2();">
  <div onclick="function_3();">
</li>

My issue is: Whenever I click one of the child elements (either the checkbox or div), it also carries out the function from the <li> --> function_1().

How can I prevent the parent element function from being called when child element is being clicked? What is the best way to achieve this?

Thanks for the help!


回答1:


Use the stopPropagation function




回答2:


Alternatively you can just return false from the child elements onclick function.



来源:https://stackoverflow.com/questions/3408138/javascript-jquery-click-element-within-element

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!