Javascript DOM Event composedPath() Method

Introduction

The composedPath() method returns all the elements the current event will propagate through.

View in separate window

<!DOCTYPE html>
<html>
<body>
<style>
div {// w  w w  .j  av  a 2  s .  c  om
  padding:50px;
  background-color:rgba(255, 0, 0, 0.2);
  text-align:center;
  cursor:pointer;
}
</style>
<script>
function func1(event) {
  document.getElementById("demo").innerHTML = event.composedPath();
}
</script>
<p id="demo"></p>
<h1>The composedPath() Method</h1>
<p>Click DIV 1:</p>
<div>DIV 2
  <div onclick="func1(event)">DIV 1</div>
</div>
</body>
</html>

The composedPath() method returns an array of objects containing the elements in the event flow, in the correct execution order.

The composedPath() method returns an Array of HTML elements.




PreviousNext

Related