Why doesn't this work?
html :
<html>
<head>
<title>test</title>
</head>
<body>
<button onclick="test21()">test</button>
</body>
</html>
javascript:
function test21(){
console.log("yey");
}
Why doesn't this work?
html :
<html>
<head>
<title>test</title>
</head>
<body>
<button onclick="test21()">test</button>
</body>
</html>
javascript:
function test21(){
console.log("yey");
}
That works fine. Here's a JSBin to prove it.
http://jsbin.com/luxesazibi/edit?html,output
More than likely you haven't loaded your script in your HTML. Where are you putting your javascript?
You have not included the script in html file.
<html>
<head>
<title>test</title>
<script>
function test21(){
console.log("yey");
}
</script>
</head>
<body>
<button onclick="test21()">test</button>
</body>
</html>
Above code snippet will run fine.
Use inspector (ctrl+shift+I) to launch console and click on the button to get results.