event.target javascript
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:
- momentjs docs
- export multiple functions react
- reload page javascript
- javascript dedupe array
- jquery scroll to top of div animate
- how to get type of variable in javascript
- react router Link does work
- time complexity array to set conversion javascript
- crypto node
- all fields entered jquery enable submit button
- what is a 0 based language
- install vue-cli
- javascript clone array of objects
- what is react native
- Elements in iteration expect to have 'v-bind:key' directives
- toLocalString
- react native class component template keyboard shortcut
- remove from array javascript
- how to setup vue
- queryselector javascript varias clases
- regex special characters javascript
- Javascript format to currency
- how to query chain an id in an id javascript
- Material-ui add circle icon