How To Modify .innerHTML Text?
So this is what I have in my body tag:
Old text Alternatively, just target the
<font>
tagdocument.querySelector('#demo > font').innerHTML = "New Text";
Solution 2:
Simply use a css style in the paragraph. "font-size" does the job.
<div class="my-block">
<p id="demo" style="font-size:25px";>
Old text<br><br>
<b><text onClick="myFunction()">Click here to continue!</text></b></p>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "New text";
}
</script>
</div>
Solution 3:
This is your code :
<div class="my-block">
<p id="demo">
<font size="5">Old text<br><br>
<b><text onClick="myFunction()">Click here to continue!</text></b></p>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "New text";
}
</script>
</font>
</div>
This is it should be :
<div class="my-block">
<p id="demo">
<font size="5">Old text<br><br>
<b><text onClick="myFunction()">Click here to continue!</text></b>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "New text";
// or u can do this too :
document.getElementById("demo").innerHTML = "<font size="5"> New text </font>";
}
</script>
</font>
</p>
</div>
Look at the <p></p>
tag
But just for your information, <font></font>
tag is not supported in HTML5
Solution 4:
Check your quotes. You can't have "" inside "" without escaping them but you can have "" inside '' vice versa. Also the 'font' tag is deprecated.
document.getElementById("demo").innerHTML = '<span style="font-weight: bold; font-size: 25px"> New text </font>';
Post a Comment for "How To Modify .innerHTML Text?"