Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > setting text, change the font

Reply
Thread Tools

setting text, change the font

 
 
Mr. x
Guest
Posts: n/a
 
      11-19-2003
Hello,

Suppose I have a table like this :

<table width = "580">
<tr align = "right" width = 760>
<td id = "current_page_inner">
<font size="4" color="lightgreen" face="arial"><b><i>
abc
</i></b>
</font>
</td>
</tr>
</table>

....
if I do in code :
current_page_inner.children(0).innerText = "bcd"
the text is changed to the new text,
and the font doesn't change,
but the font is not italic and not bold as the original.
Why ?

Thanks


 
Reply With Quote
 
 
 
 
Lasse Reichstein Nielsen
Guest
Posts: n/a
 
      11-19-2003
"Mr. x" <(E-Mail Removed)> writes:

> Suppose I have a table like this :
>
> <table width = "580">
> <tr align = "right" width = 760>
> <td id = "current_page_inner">
> <font size="4" color="lightgreen" face="arial"><b><i>
> abc
> </i></b>


I recommend against using the font, b and i tags. Use CSS to get
the same effect, that is what it was invented for.

> </font>
> </td>
> </tr>
> </table>
> ...
> if I do in code :
> current_page_inner.children(0).innerText = "bcd"


Amazing, out of the three parts of the expression on the left of
the equal sign, all are IE-specific and won't work in Mozilla.

It is bad style to refer to an element by using its name as a global
variable (bad style, and not likely to work in many browsers, including
Mozilla).
Use the W3C DOM method "getElementById" instead:
document.getElementById("current_page_inner")

The children collection is not standard code. Again, it probably works
in IE, but doesn't in Mozilla/Netscape 6+. Use the W3C DOM "childNodes"
collection instead:

document.getElementById("current_page_inner").chil dNodes[0]

Likewise "innerText" is a proprietary MS property that doesn't work in
Mozilla. The W3C method isn't as short, so I won't show it here.

> the text is changed to the new text,
> and the font doesn't change,
> but the font is not italic and not bold as the original.
> Why ?


Because the first child of the element named current_page_inner is the
font tag (in IE, in Mozilla it is a text node containing the newline
between the td and the font elements). You set the innerText of the
font tag to "bcd". That clears *all* the content of the font tag and
adds a single text node with the text "bcd".

It is equal to this W3C DOM code (ok, I will show it here

---
var elem = document.getElementById("current_page_inner").
getElementsByTagName("*")[0]; // first non-text-node
while (elem.hasChildNodes()) { // remove content
elem.removeChild(elem.lastChild);
}
elem.appendChild(document.createTextNode("bcd")); // add new content
---


/L
--
Lasse Reichstein Nielsen - http://www.velocityreviews.com/forums/(E-Mail Removed)
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Swing Font, it's Java Font? ot native? how install new font? mttc Java 2 07-03-2009 07:29 PM
How to get the text in html tag.like<div...><font...>Text</font></ =?Utf-8?B?Tmlja3k=?= ASP .Net 2 02-20-2005 03:03 PM
Font class, external font files question Karl Hungus ASP .Net 1 02-04-2004 04:26 PM
JavaRE 1.4.2 font alias in /lib/font.properties (Linux) Nick Spinel Java 0 07-25-2003 08:28 AM
physical font specified but true type font file not available Michael Glavitsch Java 1 07-15-2003 07:09 PM



Advertisments