SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard bronze trophy
    Join Date
    Apr 2003
    Posts
    4,095
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Change a CSS class value

    Dear everyone,

    Does anyone know of a way to change the text inside a container and then change the class of two containers? Thanks.

    Compuwhiz7

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes - but it can be context sensitive. What's the container? Is it just HTML, or text-only?

    Do your two containers have IDs? If not, can you give them IDs?

    etc...
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  3. #3
    SitePoint Wizard bronze trophy
    Join Date
    Apr 2003
    Posts
    4,095
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear everyone,

    The containers are HTML; they have the "class" attribute but no the "id" attribute; they can be given IDs. What would the JavaScript code be?

    Compuwhiz7

  4. #4
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Uhh - I know they are HTML. I mean - why TYPE of element.

    Both of these processes take two steps

    1) Retrieve a reference to the element
    2) Change one or more of it's properties

    In the case of text - the simplest way is to use innerHTML
    Code:
    var node = document.getElementById( 'someID' ); // step 1
    node.innerHTML = "some new text"; // step 2
    Of course, this can be refactored into one step
    Code:
    document.getElementById( 'someID' ).innerHTML = "some new text";
    Same thing goes for CSS class changes
    Code:
    var node = document.getElementById( 'someID' );
    node.className = "someNewClassName";
    You don't have to retrieve the node using getElementById, but without knowing your context, that's the only example I can offer.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  5. #5
    SitePoint Wizard bronze trophy
    Join Date
    Apr 2003
    Posts
    4,095
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear everyone,

    Thanks, Beetle!

    Compuwhiz7


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •