“JS AddEventListener” Kode Jawaban

JavaScript AddEventListener

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

Acara pendengar JavaScript

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

JS AddEventListener

var element=document.getElementById("some_id");
var listener=element.addEventListener('click',function(event){                          
            
 }); 
Grepper

window.addeventlistener

window.addEventListener("scroll", function(){
   console.log('scrolling');
});
Hossam Rashad

AddEventListener JavaScript

// The anwer of Innocent Ibis is wrong!!
// It should not have a # for the ID seens we are using getElementById
var element = document.getElementById("id");
element.addEventListener('click', function(){
	console.log("click");
});
Karamolegkos

Jawaban yang mirip dengan “JS AddEventListener”

Pertanyaan yang mirip dengan “JS AddEventListener”

Lebih banyak jawaban terkait untuk “JS AddEventListener” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya