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 :: tofixed in javascript 
Javascript :: Update an object as state with React hooks 
Javascript :: object length 
Javascript :: in js pass infinite argument in function 
Javascript :: what is diffrence between redux and context 
Javascript :: change url without reloading the page 
Javascript :: getDownload url in firebase 
Javascript :: history of react js 
Javascript :: js date minus 18 years 
Javascript :: Auto increment in firebase realtime database 
Javascript :: react-hook-form-input npm 
Javascript :: javascript remove an element from an array 
Javascript :: javascript get all elements by class starting with 
Javascript :: working of a recursive function 
Javascript :: api integration for web pages in next js 
Javascript :: call c# function from javascript 
Javascript :: discord message reply 
Javascript :: bs modal service angular pass data 
Javascript :: javaScript Math.log() Method 
Javascript :: js upload file size limit 
Javascript :: validate on submit not working 
Javascript :: jconfirm button 
Javascript :: how to add data modal target attribute in jquery 
Javascript :: millis javascript 
Javascript :: javascript merge two sorted arrays 
Javascript :: js Changing selected option by option text 
Javascript :: call function add parameter javascript 
Javascript :: print name time times in javascript 
Python :: pygame disable message 
Python :: uuid regex 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =