user3111971
user3111971

Reputation: 13

javascript to replace text on hard coded webpage

I have a hard coded webpage that I can add parts containing scripts. I need to add a script to change the word Attendees to Count throughout the page and the pages with in it. This is the code wrote and have been playing with but its not functioning.

<p> </p>
<script type="text/javascript">// <![CDATA[
document.body.innerHTML = document.body.innerHTML.replace(new RegExp("Attendees", "g"), "Count");
// ]]></script>

Upvotes: 1

Views: 1641

Answers (1)

iambriansreed
iambriansreed

Reputation: 22261

Try this:

<script type="text/javascript">
window.onload = function(){
    document.body.innerHTML = 
        document.body.innerHTML.replace(/Attendees/g, "Count");
}
</script>

You need to make sure your script runs after the page has completely loaded: window.onload\

Also check out the replace documentation.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace

Upvotes: 3

Related Questions