#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    2
    Rep Power
    0

    Question manipulation style with javascript


    Hi,

    I want to change the style (color, font-size, font-family, etc.) of normal text.

    Waht kind of tag do I have to use to make plain text accesible for that kind of manipulation?

    I tried <div id="textobj">hello world</div>

    and for the mailupation i want to use e.g.
    <select name='normal_style' size="1" OnChange="document.getElementById('textobj').style.xxxxx = normal_style.value;">
    <option value='normal' selected >Normal</option>
    <option value='italic' >Italic</option>
    </select>

    What do I have to do on OnChange at xxxxx?
    It works when using the "color" property. But when I try to change e.g. "font-size" an error occurs. Does javascript has a problem with the "-" in the identifier name?


    Thanx,
    cew
    Last edited by cew; July 3rd, 2003 at 04:37 AM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Location
    The Netherlands
    Posts
    122
    Rep Power
    12
    document.getElementById('textobj').style.innerHTML = "###"

    But innerHTML is deprecated. Do a search and you will find the most up to date specs.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    May 2003
    Posts
    1,014
    Rep Power
    15
    Does javascript has a problem with the "-" in the identifier name?
    Yep, for JavaScript you need to use fontSize, backgroundColor, borderTop, etc. instead.

    Hope this helps,
    Jeroen
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    2
    Rep Power
    0
    Originally posted by jerom
    Yep, for JavaScript you need to use fontSize, backgroundColor, borderTop, etc. instead.

    Hope this helps,
    Jeroen
    Thanx! But what about fontWeight? Is this also supported?
    I can't get it to work

    ---
    cew
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    May 2003
    Posts
    1,014
    Rep Power
    15
    fontWeight is the same story...
    Code:
    <select name='myFontWeight' size="1" onchange="document.getElementById('textobj').style.fontWeight = this.value;">
    <option value=''>Select weight</option>
    <option value='bold'>bold</option>
    </select>
    Not all possible values of fontWeight are rendered differently (depending on the font and browser afaik).

    Hope this helps,
    Jeroen

IMN logo majestic logo threadwatch logo seochat tools logo