“JS addEventListener” Respostas de código

JavaScript AddEventListener

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

ouvinte de eventos 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

Respostas semelhantes a “JS addEventListener”

Perguntas semelhantes a “JS addEventListener”

Mais respostas relacionadas para “JS addEventListener” em JavaScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código