Skip to content Skip to sidebar Skip to footer

How To Modify .innerhtml Text?

So this is what I have in my body tag:

Old text ;

Alternatively, just target the <font> tag

document.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">

<pid="demo"style="font-size:25px";>

Old text<br><br><b><textonClick="myFunction()">Click here to continue!</text></b></p><script>functionmyFunction() {
    document.getElementById("demo").innerHTML = "New text"; 
}
</script></div>

Solution 3:

This is your code :

<div class="my-block">

    <pid="demo"><fontsize="5">Old text<br><br><b><textonClick="myFunction()">Click here to continue!</text></b></p><script>functionmyFunction() {
            document.getElementById("demo").innerHTML = "New text"; 
        }
        </script></font></div>

This is it should be :

<div class="my-block">

    <pid="demo"><fontsize="5">Old text<br><br><b><textonClick="myFunction()">Click here to continue!</text></b><script>functionmyFunction() {
        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?"