[wd_asp elements=’search’ ratio=’100%’ id=1]

Replace text in a div – javascript

15th October 2015

Javascript

javascript category codehaven

Using a div called ‘noshchat’
it will search the div and replace no for replace, and hello for fish, and No comments with xx.


var theDiv = document.getElementById("noshchat");
var theText = theDiv.innerHTML;

// Replace words
theText = theText.replace("no", "replace");
theText = theText.replace("hello", "fish");
theText = theText.replace("No Comments", "xx");

theDiv.innerHTML = theText;