0

i'm trying to replace a word in a paragraph, i did it using Id selector but i need to replace the word in a p with specific classname.

<html>
<body>
<p id="demo">Visit Microsoft!</p>
<p class="demo">Visit Microsoft!</p>

<script>
window.onload = myFunction2;
function myFunction2() {
    var str = document.getElementById("demo").innerHTML; 
    var res = str.replace("Microsoft", "W3Schools");
    document.getElementById("demo").innerHTML = res;}
</script>

</body>
</html>
  • 1
    Possible duplicate of [JavaScript + find an object by ID & Class Path](http://stackoverflow.com/questions/13449032/javascript-find-an-object-by-id-class-path) – Eldelshell Jan 14 '17 at 13:01
  • 1
    Possible duplicate of [How to Get Element By Class in JavaScript?](http://stackoverflow.com/questions/3808808/how-to-get-element-by-class-in-javascript) – Vasily Liaskovsky Jan 14 '17 at 13:22

0 Answers0