Is it possible to add an eventlistener on a DIV?

后端 未结 3 431
Happy的楠姐
Happy的楠姐 2021-01-31 15:56

I know this function:

document.addEventListener(\'touchstart\', function(event) {
    alert(event.touches.length);
}, false);

But is it possibl

3条回答
  •  遥遥无期
    2021-01-31 16:26

    Of course, let's assume you have to insert text in h1 element when a user clicks on the button. It's pretty easy to bind HTML's specific element to addEventListener() method

    
    
    
    

    document.getElementById("button").addEventListener("click", function(){ document.getElementById("name").innerHTML = "Hello World!"; });

提交回复
热议问题