Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Javascript replace text

Name: Anonymous 2010-02-26 4:59

Hello. Can someone tell me please how to replace text with Javascript? I need to replace some 4chan's posters names.

I've tried to modify this example but it didn't worked.

http://www.randomsnippets.com/2008/03/07/how-to-find-and-replace-text-dynamically-via-javascript/

That's what I did.

var commentposternameText = "";
     if (commentposternameText.length == 0) {
          commentposternameText = document.getElementByClass("commentpostername").innerHTML;
     }
     var match = new RegExp("Anonymous", "g");
     var replaced = "";
     if ("hurrdurr".length > 0) {
          replaced = commentposternameText.replace(match, "hurrdurr");
     }
     else {
          var boldText = "<div style=\"background-color: yellow; display: inline; font-weight: bold;\">" + "Anonymous" + "</div>";
          replaced = commentposternameText.replace(match, boldText);
     }
     document.getElementByClass("commentpostername").innerHTML = replaced;


commentpostername is where Anonymous is:
<span class="commentpostername">Anonymous</span>

Anonymous is what I'm trying to replace. It's just for example

hurrdurr is what I'm trying to replace Anonymous with

Name: Anonymous 2010-02-26 5:00

4us6hrt

Name: Anonymous 2010-02-26 12:48

Hahaha oh wow!

Use code tags next time.

Name: Anonymous 2010-02-26 12:50

commentposternameText

Name: !TroLL.TKzc 2010-02-26 16:02

Replace "commentpostername" by "postername" (not trolling).

Don't change these.
Name: Email:
Entire Thread Thread List