“StopimmediatePropagation gegen Stopppropagation” Code-Antworten

StopimmediatePropagation gegen Stopppropagation

<!---- stopImmediatePropagation() vs stopPropagation() ----------------->

`stopPropagation` allows other event handlers on the SAME ELEMENT 
on the SAME EVENT to be executed, while `stopImmediatePropagation`
prevents this.

<script>
el.addEventListener( "click", e => e.stopImmediatePropagation() )
el.addEventListener( "click", e => console.log("This will not run.") )
</script>

<!----------------- stopImmediatePropagation() vs stopPropagation() ---->
KostasX

StopimmediatePropagation

<!-- index.html -->

<div id="credit">Procrastination for Dummies</div> 
Copy code
JAVASCRIPT
/* script.js */

const credit = document.querySelector("#credit");

credit.addEventListener("click", function(event) {
  console.log("Nah, I'll do it later");
});

credit.addEventListener("click", function(event) {
  console.log("I WILL do it tomorrow");
  event.stopImmediatePropagation();
});

credit.addEventListener("click", function(event) {
  console.log("Why do I have so much work piled up?!");
});

/* Clicking on the div block will print to the console:

  Nah, I'll do it later
  I WILL do it tomorrow

*/ 
Cruel Cormorant

Ähnliche Antworten wie “StopimmediatePropagation gegen Stopppropagation”

Fragen ähnlich wie “StopimmediatePropagation gegen Stopppropagation”

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen