Forum Moderators: open

Message Too Old, No Replies

Adding HTML tags in JS getElementbyID

Word of the day generator, need to add bold tags

         

catcherintherye51

3:32 pm on Aug 31, 2006 (gmt 0)

10+ Year Member



I gave a "Word of the Day" generator that works great, but I want to be able to show the word itseld in bold, the definition normal.


<script type="text/JavaScript">
var quote = new Array();
quote[0] = 'Word 1: Lorem ipsum dolor sit amet, consectetuer adipiscing elit.';
quote[1] = 'Word 2: Nullam commodo venenatis elit. In aliquam.';
quote[2] = 'Word 3: Sed vitae risus ac urna pharetra tristique.';
var firstDate = new Date(2005,0,1);//start date (yyyy,m,d) - m=0=January, m=1=February
var today = new Date();//today
var dif = Math.floor((today-firstDate)/1000/60/60/24);//difference in days
while(dif>=qlen){//calculate the index of the quote of the day
dif=dif-qlen;//restart the array index if the difference is greater that the array's length
}
var todayQuote = quote[dif];//the quote of the day
onload = function(){document.getElementById('q').firstChild.data = todayQuote}
</script>

For example,in the script above I want <b>Word 1:</b> to be in bold, the rest normal.

Any way to do this?

Fotiman

4:01 pm on Aug 31, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



quote[0] = '&lt;b&gt;Word 1:&lt;\/b&gt; Lorem ipsum dolor sit amet, consectetuer adipiscing elit.';

[edited by: Fotiman at 4:01 pm (utc) on Aug. 31, 2006]

catcherintherye51

6:55 pm on Aug 31, 2006 (gmt 0)

10+ Year Member



Thanks! I'll give it a shot.

catcherintherye51

8:02 pm on Sep 7, 2006 (gmt 0)

10+ Year Member



Well, I tried it but

"&lt;b&gt;Word 1:&lt;\/b&gt; Lorem ipsum dolor sit amet, consectetuer adipiscing elit."

appeared. Is there another way to bold Word 1? Something to do with innerHTML?

alanderson

9:33 pm on Sep 7, 2006 (gmt 0)

10+ Year Member



yes it is, don't worry about the html entities for < > just use <B> tags as you normally would and change this line;

onload = function(){document.getElementById('q').firstChild.data = todayQuote}

to this;

onload = function(){document.getElementById('q').innerHTML = todayQuote}

catcherintherye51

4:29 pm on Sep 8, 2006 (gmt 0)

10+ Year Member



Thanks! Worked great!