+ 4
How to check if a button is clicked using javascript?
I want to check if a button is clicked,without defining any extra function.
5 Answers
+ 6
<!-- HTML -->
<button onclick="alert('you clicked me') ">Ben</button>
+ 2
Ya'iko its not helping.JS console reads,onclick cannot read null pointer.
+ 1
<button>Click</button>
JS
===
var isClicked= false
var btn=document.querySelector("button")
btn.onclick= function(){
isCliked= true
alert("You clicked the. button")
}
+ 1
You should have wrote the codes inside the function
window.onload=function(){
//Type in the code here
}
+ 1
Ya'iko ,in this code I want to check if the right button is clicked.Due to the requirements cannot define an extra function.
https://code.sololearn.com/W52ygoE45Lc3/?ref=app