Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am attempting to change the text of a paragraph with javascript as shown but nothing seem to be changing on my PC. What is wrong?

HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script>

function ChangeText(Mynumber)
{
 	return 'Paragraph Changed';
}

function Reset()
{
		
	document.getElementById("demo").innerHTML = ChangeText(1)';
}



</script>
</head>


<body>

<h1>My Web Page</h1>

<p id="demo">A Paragraph</p>

<button type="button" onclick="Reset()">Try it</button>

</body>
</html>
Posted
Comments
Kornfeld Eliyahu Peter 10-Jan-16 8:49am    
The only problem I can see is that quote (') here:
document.getElementById("demo").innerHTML = ChangeText(1)';
It creates a JavaScript syntax error (can see it in your debugger)...
Gbenbam 10-Jan-16 8:55am    
Thanks. I fixed it. Everything is fine now.

1 solution

You made a small typo here:
JavaScript
document.getElementById("demo").innerHTML = ChangeText(1)';

There is a single quote before the semicolon, which mustn't be there.
 
Share this answer
 
Comments
Wendelius 10-Jan-16 8:53am    
Nicely spotted!
Thomas Daniels 10-Jan-16 8:56am    
Thanks!
Gbenbam 10-Jan-16 8:56am    
Thanks. I have fixed it.
Thomas Daniels 10-Jan-16 8:56am    
You're welcome!
Sergey Alexandrovich Kryukov 10-Jan-16 13:08pm    
5ed.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900