Bear with me guys.. Im new to JavaScript AND StackOverflow...
Here is my problem :
I have created a simple piece of code, with 3 buttons that should change a text (innerHTML) when pressed... but it's not working.. :-(
What am I doing wrong ?
I have checked W3Schools for clues.. but no dice..
<head>
<title>JavaScript Table</title>
<style>
body{
text-align: center;
font-family: arial;
}
</style>
<script>
function red(){
document.getElementById("tekst").innerHTML = "Red";
}
function green(){
document.getElementById("tekst").innerHTML = "Green";
}
function blue(){
document.getElementById("tekst").innerHTML = "Blue";
}
</script>
</head>
<body>
<h2 id="tekst">Color</h2>
<button onsubmit="red()">Red</button>
<button onsubmit="green()">Green</button>
<button onsubmit="blue()">Blue</button>
</body>
</html>```
You need to change
onsubmit
toonclick
. You can also add an event in the script:HTML:
JavaScript: