In JavaScript, you can use the event.stopPropagation() method to handle event bubbling. The event.stopPropagation() method prevents the event from bubbling to the parent element and prevents any parent event handlers from being executed.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
When adding events to Dom elements, sometimes you will encounter event bubbling. The processing method is as follows:
Execute event.stopPropagation to prevent event bubbling
$("#Tab1 .close").live("click", function (event) { droptab(this);//业务逻辑处理函数 event.preventDefault(); event.stopPropagation(); return false; });
The event.stopPropagation()
method prevents events from bubbling to the parent element and prevents any parent event handlers from being executed.
Tip: Please use the event.isPropagationStopped()
method to check whether this method is called on the specified event.
[Recommended learning: javascript advanced tutorial]
The above is the detailed content of How JavaScript handles event bubbling. For more information, please follow other related articles on the PHP Chinese website!