Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

addeventlistener to button 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
})
Comment

btn.addeventlistener

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

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

javascript addeventlistener button

/*
HTML
<button id="buttonId" >Click here</button>
*/

document.getElementById('buttonId').addEventListener('click', function(event) {
	const button = event.target;
	button.innerText = (Number(button.innerText) || 0) + 1;
})
Comment

PREVIOUS NEXT
Code Example
Javascript :: convert data into json format in javascript 
Javascript :: javascript pushstate 
Javascript :: javascript element read attribute 
Javascript :: react js create element 
Javascript :: add class when element in viewport vanilla javascript 
Javascript :: how to split two digit number in javascript 
Javascript :: javascript validate password 
Javascript :: js querySelectorAll map sample 
Javascript :: avascript sum of arguments 
Javascript :: discordjs eval 
Javascript :: get first element by class name jquery 
Javascript :: find longest word in string javascript 
Javascript :: checkbox change event javascript 
Javascript :: sample json 
Javascript :: get first day of the week of a given date javascript js 
Javascript :: send message whatsapp javascript 
Javascript :: how to catch and throw error js 
Javascript :: array to string javascript without commas 
Javascript :: jquery get meta value 
Javascript :: jquery on click function 
Javascript :: invisible character javascript 
Javascript :: get random percentage javascript 
Javascript :: simplebar react 
Javascript :: open modal js 
Javascript :: iframe content in chrome console 
Javascript :: How to remove title in material-table 
Javascript :: get name of day javascript 
Javascript :: Uncaught TypeError: $(...).DataTable is not a function 
Javascript :: object length javascript 
Javascript :: jquery window offset top 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =