[Javascript] styling text

Troy III Ajnej trojani2000 at hotmail.com
Sat Dec 1 09:06:07 CST 2007


"This only takes care of the first occurrence of the word."
 
That's what you were aiming for, -isn't it?!
 
This will do the same:
 
function init(){ var theList=document.getElementById("theList") var listItem = theList.getElementsByTagName('li')
for (i=0;i< listItem.length; i++){ var notion = listItem[i].getElementsByTagName('span')  notion[2].innerHTML=  notion[2].innerHTML.replace(notion[0].innerHTML,  notion[0].innerHTML.bold().fontcolor('blue')) }}
 
..but will not clear the "word" if applyed for the seccond time.
nice html structure bye the way!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                        Troy III                            progressive art enterprise~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


From: petersen at ma.medias.ne.jpDate: Sat, 1 Dec 2007 16:53:01 +0900To: javascript at lists.evolt.orgSubject: Re: [Javascript] styling text

Have you tried using innerHTML?  As in span.innerHTML = span.innerHTML.replace("dirty", "<span class='blueWord'>dirty</span");It may not be elegant enough for some, but it seems to do the job.I could only get this to work in Safari 3. It didn't work in Firefox or Opera. I'm not sure why. 
I tried the following, which did work. It is even more inelegant. This only takes care of the first occurrence of the word.


function init(){
var list=document.getElementById('theList');
var theItems=list.getElementsByTagName('li');
for (i=0;i<theItems.length; i++){
var oneItem=theItems[i].getElementsByTagName('span');
var headWord=oneItem[0].firstChild.nodeValue;
var sentence=oneItem[2].firstChild.nodeValue;
oneItem[2].innerHTML=sentence.replace(headWord, headWord.bold().fontcolor("blue"));
}
}

At any rate, thank you.

Scott Petersen

From: Scott Petersen petersen at ma.medias.ne.jpI have a problem I can't seem to solve. I want to take this markup: 


dirty ?? I have to clean my room. It is dirty. and color the word "dirty" in the sentence blue, or set it off in some other way. I thought to create a span element and style it with CSS. However, I am not able to replace the plain text with the span element. I could mark the word up to begin with, but for work flow I thought I might try to let javascript do the work. Any thoughts? Scott Petersen By the way, the Japanese is merely a gloss of the English.
_________________________________________________________________
Your smile counts. The more smiles you share, the more we donate.  Join in.
www.windowslive.com/smile?ocid=TXT_TAGLM_Wave2_oprsmilewlhmtagline
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20071201/9f176542/attachment.htm>


More information about the Javascript mailing list