I want to trigger some JavaScript code when the button is clicked.
I want that when the button is clicked console.log()
is triggered.
My attempt:
corel.html :
<!DOCTYPE html>
<html>
<head>
<title>Corelation</title>
<script src="jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="corel.js"></script>
</head>
<body>
<form id="tableVar">
Variable 1: <input type="text" id="var1"><br>
Variable 2: <input type="text" id="var2"><br>
<button onclick="myFunction()">Click me</button> <!-- type is button to not refresh -->
</form>
</body>
</html>
corel.js :
console.log("iniating app ...");
function myFunction() {
console.log('yeah');
}
I do not understand what does not work ?
The button is making the form submit hence you need to use preventDefault()
See this demo
Use this code,
HTML
Corel.js