i want text show "here" example, doesn't work. text changes word need stays on fixed position. access word.
what doing wrong?
function myfunction() { var x = document.getelementbyid("demo"); var y = x.slice(16,19); document.getelementbyid("demo").innerhtml = y; } <p id="demo">changable tekst here</p> <button onclick="myfunction()">try it</button>
x dom node object, cannot use string methods on it. use innerhtml property on innerhtml of element.
var x = document.getelementbyid("demo").innerhtml; // ^^^^^^^^^ also, use x.slice(16, 20); word here text.
<p id="demo">changable tekst here</p> <button onclick="myfunction()">try it</button> <script> function myfunction() { var x = document.getelementbyid("demo").innerhtml; var y = x.slice(16, 20); document.getelementbyid("demo").innerhtml = y; } </script>
Comments
Post a Comment