Answers for "what is addevent listener ?"

34

javascript addeventlistener

var element = document.getElementById("#id");
element.addEventListener('click', function(){
	console.log("click");
});
Posted by: Guest on May-20-2020
7

event listener javascript

document.querySelector('div').addEventListener('click', () => {
  console.log('div clicked');
});
Posted by: Guest on October-05-2020
5

javascript event listener

element.addEventListener("click", function(){ 
   element.innerText = "something"; 
});
Posted by: Guest on February-19-2020
0

addEventListener

<body style="height: 5000px">
 <script>
    function snap(destination) {
        if (Math.abs(destination - window.scrollY) < 3) {
            scrollTo(window.scrollX, destination);
        } else if (Math.abs(destination - window.scrollY) < 200) {
            scrollTo(window.scrollX, window.scrollY + ((destination - window.scrollY) / 2));
            setTimeout(snap, 20, destination);
        }
    }
    var timeoutId = null;
    addEventListener("scroll", function() {
        if (timeoutId) clearTimeout(timeoutId);
        timeoutId = setTimeout(snap, 200, parseInt(document.getElementById('snaptarget').style.top));
    }, true);
 </script>
 <div id="snaptarget" class="snaptarget" style="position: relative; top: 200px; width: 100%; height: 200px; background-color: green"></div>
</body>
Posted by: Guest on May-19-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language