Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
12
rated 0 times [  15] [ 3]  / answers: 1 / hits: 153105  / 7 Years ago, wed, march 1, 2017, 12:00:00



<button onclick=hello()>Hello</button>

<script>
function hello() {
alert('Hello');
}
</script>





This is my code. But it's not working. When I click on the button nothing happens.


More From » html

 Answers
48

How about this?



<button id=hellobutton>Hello</button>
<script>
function hello() {
alert('Hello');
}
document.getElementById(hellobutton).addEventListener(click, hello);
</script>


P.S. You should place hello() above of the button.


[#58719] Tuesday, February 28, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
maryann

Total Points: 600
Total Questions: 104
Total Answers: 97

Location: Sint Maarten
Member since Tue, Mar 29, 2022
2 Years ago
maryann questions
Fri, Oct 15, 21, 00:00, 3 Years ago
Thu, Aug 13, 20, 00:00, 4 Years ago
Wed, Jul 17, 19, 00:00, 5 Years ago
Mon, Dec 17, 18, 00:00, 6 Years ago
;