SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    May 2006
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to give class name dynamically to HTML Tag

    Hi Friends..
    I have a set of of div tags with different ID.
    I want to give them a class name during page loading dynamically according to IDs.
    How to do that,can u please help!! I am beginer in Javascript.

    Thanx,
    Prabir

  2. #2
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    document.getElementById("your-id").className = "your-class";
    Birnam wood is come to Dunsinane

  3. #3
    SitePoint Member
    Join Date
    May 2006
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thx AutisticCuckoo..
    Its working beautifully.

  4. #4
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    setting attributes, like class names, is typically done like this...
    Code:
    document.getElementById("your-id").setAttribute("class", "your-class");
    however since IE has to be different - the way AutisticCuckoo pointed out has to be used for IE to change classes properly.


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
  •