JAVASCRIPT EVENT.TARGET
Using the event.target property together with the element.tagName property to find out which element triggered a specified event:
<body onclick="myFunction(event)">
<p>Click on any elements in this document to find out which element triggered the onclick event.</p>
<h1>This is a heading</h1>
<button>This is a button</button>
<p id="demo"></p>
<script>
function myFunction(event) {
var x = event.target;
document.getElementById("demo").innerHTML = "Triggered by a " + x.tagName + " element";
}
</script>event.target returns the node that was targeted by the function.
This means you can do anything you would do with any other node like one
you'd get from document.getElementByIdconst theTarget = someEvent.target;
Also in JavaScript:
- javascript give class to element
- angular import service
- event loop in javascript
- how to create multiple folders at once in node js
- vue js cdn
- react mid senior dev interview questuions
- js filter items by index
- how to get create an array in javascript
- asking questions javascript in console
- string contains in javascript
- algolia react hits
- to capital case javascript
- how to change css variable in javascript
- how to trigger events when the document loads in js
- jquery select self and siblings
- extension for local storage in angular 8
- install node js 14
- enviando post angular 8
- javascript get file extension from string
- set element at index javascript array and create new array
- material css
- javascript pad with leading zeros
- express payloadtoolarge request entity too large bodyParser raw-body hydra-express
- sum of odd numbers in an array javascript