+ 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.

21st Jul 2018, 6:35 AM
Aanisha Bhattacharyya
Aanisha Bhattacharyya - avatar
5 Antworten
+ 6
<!-- HTML --> <button onclick="alert('you clicked me') ">Ben</button>
21st Jul 2018, 7:36 AM
Nomeh Uchenna Gabriel
Nomeh Uchenna Gabriel - avatar
+ 2
Ya'iko its not helping.JS console reads,onclick cannot read null pointer.
21st Jul 2018, 7:09 AM
Aanisha Bhattacharyya
Aanisha Bhattacharyya - avatar
+ 1
<button>Click</button> JS === var isClicked= false var btn=document.querySelector("button") btn.onclick= function(){ isCliked= true alert("You clicked the. button") }
21st Jul 2018, 7:05 AM
Dlite
Dlite - avatar
+ 1
You should have wrote the codes inside the function window.onload=function(){ //Type in the code here }
21st Jul 2018, 7:12 AM
Dlite
Dlite - avatar
+ 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
21st Jul 2018, 7:14 AM
Aanisha Bhattacharyya
Aanisha Bhattacharyya - avatar