Home >Web Front-end >JS Tutorial >Specific ideas and implementation of preventing child elements from inheriting parent element events_javascript skills

Specific ideas and implementation of preventing child elements from inheriting parent element events_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:34:591458browse
Copy code The code is as follows:






#p_box includes #p_cont, when click anywhere in the #p_box area (including #p_cont), an event will be triggered. If you want to prevent an event from being triggered when the #p_cont area is clicked, you need to add code to prevent the event from bubbling in the #p_cont area.
becomes
Copy the code The code is as follows:





function a(){
//Here is the code for a event
}
function stopBubble(e) {
if (e && e.stopPropagation) {//Non-IE browser
e.stopPropagation();
}
else {//IE browser
window.event.cancelBubble = true;
}
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn