Change button text using onclick event

 

The onclick event occurs when the user clicks on an HTML element.

 

Use theaddEventListener() method to attach a "click" event to a HTML element. You only need to replace you button id wth "someId"

document.getElementById("someId").addEventListener("click", function(){

		if (this.value=="Some text") {
			this.value = "other text";
		}
else{ 
			this.value = "Some text";
		};
});

Tags:

Share:

Related posts