Reputation: 11
Forgive my ignorance, because I'm pretty new to programing. I've been beating out my brains on this one. Can anyone tell me why this doesn't work? I know it will be something dumb:
addText(){
document.getElementById("demo").innerHTML = "New Content";
}
<!DOCTYPE html>
<html>
<head>
<title>InnerHTML Example</title>
</head>
<body>
<p id="demo">
<Button onclick="addText()">Change</Button>
Original Content
</p>
</body>
</html>
Upvotes: 1
Views: 24
Reputation: 499
You haven't declared addTest()
as a function. Should be:
<script>
function addTest() {
...
}
</script>
function addText() {
document.getElementById("demo").innerHTML = "New Content";
}
<!DOCTYPE html>
<html>
<head>
<title>InnerHTML Example</title>
</head>
<body>
<p id="demo">
<Button onclick="addText()">Change</Button> Original Content
</p>
</body>
</html>
Upvotes: 1