Links

Lists

Latest Updates

Ruby On Rails List
Python list
Advanced Java
The JavaScript List
Apache Users
Full Disclosure
Linux Security

Search the archives!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Javascript] Comparing Strings


  • From: wdlists at triche-osborne.com (Triche Osborne)
  • Subject: [Javascript] Comparing Strings
  • Date: Thu Aug 25 09:58:23 2005

Timothy White wrote:
> 
> Hmmm. Well that doesn't work cause I want to put HTML in there.
> Is there any other way for HTML? Or is it just InnerHTML?
> Otherwise I might try formatting the data differently.
> 

That depends on how consistently formatted your replacement stuff is, or 
how easily you can get at the formatting. For example, if you want to 
replace the text in this DIV:

<div id="replaceThis">Text to be replaced.</div>

With this:

<p>"Hi there!"</p>

It requires something like this:

var replacementText = document.createTextNode("Hi there!");
var newP = document.createElement('p');

var theNode = document.getElementById("replaceThis");
theNode.removeChild(theNode.firstChild);

newP.appendChild(replacementText);
theNode.appendChild(newP);

If your formatting is inconsistent--different elements, some with class 
codes, etc.--you could store it in array form and use the array elements 
to build the replacement. For instance, you might have:

var replacements = new Array();
replacements[0] = ("Hi there!/span");
replacements[1] = ("Bonjour!/"p","span"/"error");

. . . where the slash and comma provide split markers, or you can use a 
multi-dim array instead. You can create your own schema for it. As long 
as it's consistent, it will give you something to hang your hat on when 
you're processing.

Triche