“Event JavaScript CurrentTarget” Kode Jawaban

Event JavaScript CurrentTarget

function hide(e){
  e.currentTarget.style.visibility = 'hidden';
  console.log(e.currentTarget);
  // When this function is used as an event handler: this === e.currentTarget
}

var ps = document.getElementsByTagName('p');

for(var i = 0; i < ps.length; i++){
  // console: print the clicked <p> element
  ps[i].addEventListener('click', hide, false);
}
// console: print <body>
document.body.addEventListener('click', hide, false);

// Click around and make paragraphs disappear
Himanshu Jangid

CurrentTarget JavaScript

//Javascript
document.getElementById("foo").onclick = (e) => {
	e.target.style.backgroundColor = "#333";
	console.log(e.target.value)
    
    // Expected Output: "Hello World!"
}

//HTML
<input id="foo" type="text" value="Hello World!">
Q_Q

Jawaban yang mirip dengan “Event JavaScript CurrentTarget”

Pertanyaan yang mirip dengan “Event JavaScript CurrentTarget”

Lebih banyak jawaban terkait untuk “Event JavaScript CurrentTarget” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya