“btn.addeventlistener” Kode Jawaban

AddEventListener ke Tombol JavaScript

const button = document.getElementById('yourButton');
button.addEventListener('click', (event) => {
	// Do something with the event
    // https://developer.mozilla.org/en-US/docs/Web/API/Event
})
I_Like_Cats__

Pendengar acara JavaScript OnClick

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

btn.addeventlistener

<!--on html-->
<button>Click Me!</button>

/*js code*/
let btn = document.querySelector('button').addEventListener('click', () => {
    console.log('"Ohh!" Button clicked!')
});
Sleepy Scarab

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya