Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js event target

const button = document.querySelector(".button");

button.addEventListener("click", function (evt) {
    // the event Target variable will contain the button element that we clicked on
    const eventTarget = evt.target;
    eventTarget.setAttribute("disabled", true);
}); 
Comment

javascript .target

// Make a list
const ul = document.createElement('ul');
document.body.appendChild(ul);

const li1 = document.createElement('li');
const li2 = document.createElement('li');
ul.appendChild(li1);
ul.appendChild(li2);

function hide(evt) {
  // e.target refers to the clicked <li> element
  // This is different than e.currentTarget, which would refer to the parent <ul> in this context
  evt.target.style.visibility = 'hidden';
}

// Attach the listener to the list
// It will fire when each <li> is clicked
ul.addEventListener('click', hide, false);
Comment

event.target javascript

const theTarget = someEvent.target;
Comment

JAVASCRIPT EVENT.TARGET

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.getElementById
Comment

event.target

// Make a list
const ul = document.createElement('ul');
document.body.appendChild(ul);

const li1 = document.createElement('li');
const li2 = document.createElement('li');
ul.appendChild(li1);
ul.appendChild(li2);

function hide(evt) {
  // evt.target refers to the clicked <li> element
  // This is different than evt.currentTarget, which would refer to the parent <ul> in this context
  evt.target.style.visibility = 'hidden';
}

// Attach the listener to the list
// It will fire when each <li> is clicked
ul.addEventListener('click', hide, false);
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to put multiple conditions in if statement node .js 
Javascript :: × error: element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. you likely forgot to export your component from the file it 
Javascript :: what is computed property in vue js 
Javascript :: react native version 
Javascript :: javascript check item is checkbox 
Javascript :: how to delete an element from an array in javascript 
Javascript :: sort function explained javascript 
Javascript :: schema 
Javascript :: module.exports equivalent typescript 
Javascript :: useselector 
Javascript :: node js mongodb update nested object 
Javascript :: functions javascript 
Javascript :: javascript load content from file 
Javascript :: Filtering an array for unique values 
Javascript :: in js pass infinite argument in function 
Javascript :: change css variable with javascript 
Javascript :: javascript first class functions 
Javascript :: function in javascript 
Javascript :: javascript remove an element from an array 
Javascript :: array example 
Javascript :: print a number with commas as thousands separator 
Javascript :: svg react native 
Javascript :: array js 
Javascript :: moment-recur cdn 
Javascript :: ssl certificate nodejs 
Javascript :: how do you calculate what percentage a number is of another number 
Javascript :: find the second largest number in array javascript 
Javascript :: javascript free code editors 
Javascript :: set route on button in angular 
Javascript :: JS copy image 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =