Reputation: 13
So I'm trying to make a page display different paragraphs for each button pressed. However I keep getting some errors where the button will not run the function correctly. Ex
function examplefunction() {
document.getElemtentById("paragraphtobechanged").innerHTML = "When I put more "" it fails in other words it will not write this part."
}
<button onclick="examplefunction()">Change Paragraph</button>
<p id="paragraphtobechanged"></p>
Upvotes: 1
Views: 39
Reputation: 111
The issue here is with the actual string.
// Option 1
"When I put more \"\" it fails in other words it will not write this part."
// Option 2
'When I put more "" it fails in other words it will not write this part.'
Note: Option 2 works with your case but if you're using both single-quotes and double-quotes within your actual string you'll have to escape one or the other.
Upvotes: 0
Reputation: 2557
@TheDude was on the right track, but there's something else. You spelt element wrong in your example:
function examplefunction() {
V
document.getElementById("paragraphtobechanged").innerHTML = "When I put more \"\" it fails in other words it will not write this part."
}
Upvotes: 1
Reputation: 3952
It should be:
function examplefunction() {
document.getElemtentById("paragraphtobechanged").innerHTML = "When I put more \"\" it fails in other words it will not write this part."
}
You need to escape the double quotation marks. Or you can do:
function examplefunction() {
document.getElemtentById("paragraphtobechanged").innerHTML = 'When I put more "" it fails in other words it will not write this part.'
}
Upvotes: 2