setting text, change the font

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mr. x

    setting text, change the font

    Hello,

    Suppose I have a table like this :

    <table width = "580">
    <tr align = "right" width = 760>
    <td id = "current_page_i nner">
    <font size="4" color="lightgre en" face="arial"><b ><i>
    abc
    </i></b>
    </font>
    </td>
    </tr>
    </table>

    ....
    if I do in code :
    current_page_in ner.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 :)


  • Lasse Reichstein Nielsen

    #2
    Re: setting text, change the font

    "Mr. x" <a@b.com> writes:
    [color=blue]
    > Suppose I have a table like this :
    >
    > <table width = "580">
    > <tr align = "right" width = 760>
    > <td id = "current_page_i nner">
    > <font size="4" color="lightgre en" face="arial"><b ><i>
    > abc
    > </i></b>[/color]

    I recommend against using the font, b and i tags. Use CSS to get
    the same effect, that is what it was invented for.
    [color=blue]
    > </font>
    > </td>
    > </tr>
    > </table>
    > ...
    > if I do in code :
    > current_page_in ner.children(0) .innerText = "bcd"[/color]

    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.getEle mentById("curre nt_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.getEle mentById("curre nt_page_inner") .childNodes[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.
    [color=blue]
    > 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 ?[/color]

    Because the first child of the element named current_page_in ner 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.getEle mentById("curre nt_page_inner") .
    getElementsByTa gName("*")[0]; // first non-text-node
    while (elem.hasChildN odes()) { // remove content
    elem.removeChil d(elem.lastChil d);
    }
    elem.appendChil d(document.crea teTextNode("bcd ")); // add new content
    ---


    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    Working...