“Document.AddeventListener” Kod odpowiedzi

AddEventListener Hover JS

let test = document.getElementById("test");

test.addEventListener("mouseover", function( event ) {
  alert("mouse over test!")
  , false);
Jeff Spicoli

JavaScript onClick Event Listener

document.getElementById("myBtn").addEventListener("click", function() {
  alert("Hello World!");
});
Batman

JavaScript AddEventListener

var element = document.getElementById("#id");
element.addEventListener('click', function(){
	console.log("click");
});
Innocent Ibis

JavaScript Event Listener

const element = document.querySelector(".class__name");

element.addEventListener("click", () => {
	console.log("clicked element");
});
Levaillant's Barbet

JS Document.AddeventListner

//Syntax
target.addEventListener(type, listener);
//Example 
document.addEventListener("click", modifyText);
//HTML
<table id="outside">
  <tr><td id="t1">one</td></tr>
  <tr><td id="t2">two</td></tr>
</table>
//JavaScript
// Function to change the content of t2
function modifyText(new_text) {
  const t2 = document.getElementById("t2");
  t2.firstChild.nodeValue = new_text;
}
// Function to add event listener to table
const el = document.getElementById("outside");
el.addEventListener("click", function(){modifyText("four")}, false);
Encouraging NeoBliz

Document.AddeventListener

java script
icon ke

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu