Reputation: 144
Code didn't work and still return 'f' world after function call, what's wrong with my code? thanks for help
HTML:
<html>
<head>
<script type="text/javascript" src="functions.js"></script>
</head>
<body onload="changeText()">
<p id="P1">
fu
</p>
</body>
</html>
JS:
function changeText(){
document.getElementById("p1").innerHTML = "slm"
}
Upvotes: 0
Views: 128
Reputation: 906
please try this one, problem was that you can't call function changeText()
:
<html>
<head>
<script type="text/javascript">
function changeText(){
document.getElementById("P1").innerHTML = "slm"
}
</script>
</head>
<body onload="changeText()">
<p id="P1">fu</p>
</body>
</html>
Upvotes: 0
Reputation: 156
ID's in Javascript are case sensitive (all attributes are). The ID in the HTML is P1
but you're looking for p1
so it's not finding it.
Upvotes: 2
Reputation: 59
You are accessing the wrong ID Note P is capital letter, try:
document.getElementById("P1").innerHTML = "slm"
Upvotes: 0
Reputation: 754
Because the selector is case sensitive. Try to use P1 instead of p1: document.getElementById("P1").innerHTML = "slm"
Upvotes: 3