Monday, 15 September 2014

javascript - Stop click event propagation -


When a user clicks on it, I'm trying to highlight any DOM element of a certain web page I am For that purpose, I repeat through all the elements of the current element and disable any functionality (like I can click and can not be redirected):

  Var elems = window.document.getElementsByTagName ('*'); For (var i = 0; i & lt; elems.length; i ++) {ames [i] .onclick = function (e) {e.preventDefault (); }  

This is the thing when a user clicks, many click events are removed, because each element has TAS behavior, and I should avoid the non-lightlight.

Any thoughts or ideas to improve any options? Thanks a lot!

P / D: It should be pure JS

You will need: First of all, you really want to add a event , do not want to redefine its click behavior, and secondly, you do not want it to be bubble Want to try it through the dom:

  var elems = window.document.getElementsByTagName ('*'); Use the addEventListener to hear for // (var i = 0; i & lt; elems.length; i ++) {// // attachEvent using the old version of IE, but I think it is irrelevant is. AIIMS [i] .addEventListener ("click", function (e) {e.preventDefault (); // Use prevention. For wrapping this clip, wrap the parent to prevent the element - because a child One click is technically a click as a parent also. E.stopImmediatePropagation ();}); }  

There is more to read:

Add Event Listener:

Stop Promotional Promotion:

As a brave editor, you can pass false as the third argument of addEventListener and this is basically the same thing Does but is less comfortable and some extra things are also, so I did not choose the default because it is easy to understand that you are blocking the promotion.


No comments:

Post a Comment