Search This Blog

Friday, 29 July 2016

How to replace the word in the paragraph using javascript?

Html Page:

<p id="demo">Visit Microsoft!</p>
<button onclick="myFunction()">Try it</button>

Javascript page:

<script>
    function myFunction() {
        var str = document.getElementById("demo").innerHTML;
        var res = str.replace("Microsoft", "InfoItbook");
        document.getElementById("demo").innerHTML = res;
    }
</script>

Output:

Visit InfoItbook

No comments:

Post a Comment