I can’t find the problem with my simple code. The button shows, but the alert pop-up doesn’t show when I click on it.
What am I doing wrong?
<DOCTYPE! html>
<html>
<body>
<h1>This will be a test for Javascript</h1>
<button> onclick="myFunction()">I like it</button>
<script>
function myFunction() {
alert("are you sure?");
}
</script>
</body>
</html>
pnuts
59.8k11 gold badges93 silver badges141 bronze badges
3 Answers 3
Problem in smart quotes. Use
"
quotes.
Sign up to request clarification or add additional context in comments.
Comments
<button onclick="ok()">Ok</button>
<script>
function ok() {
alert("ok");
}
</script>
answered Aug 24, 2017 at 3:23
Saw Zin Min Tun
6423 silver badges9 bronze badges
1 Comment
heysulo
What he needs is JavaScript. Not jQuery
- Use
""not"in your code - Try to write your js code before html "button" code.
- And try also to add a comma in the end of onclick script.
Comments
default
"(smart quote) instead of". Change it and check again. And open your browser's developer (usually <kbd>F12</kbd> and monitor the console tab. It will provide you some hints to correct your problem. When it comes to learning JavaScript, Browser console is your friend.