Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old May 23rd, 2006, 7:48 PM   #1
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 2,024
Rep Power: 6 Sane will become famous soon enough
Send a message via MSN to Sane
How To Change The Style/Class Of An Object?

How do I change the style/class of an object with javascript?

/* GET AN OBJECT */

var objects = new Array();
var type = 0;
if (document.getElementById)
{
    type = 1;
}
else if (document.all)
{
    type = 2;
}
else if (document.layers)
{
    type = 3;
}
function get_object(idname)
{
    if (typeof(objects[idname]) == "undefined")
    {
        if (type == 1)
        {
            objects[idname] = document.getElementById(idname);
        }
        else if (type == 2)
        {
            objects[idname] = document.all[idname];
        }
        else if (type == 3)
        {
            objects[idname] = document.layers[idname];
        }
    }
    return objects[idname];
}


Then I try to change the class/style like so:
x = get_object('some_id');
x.style = 'background-color: #000';

I get the error: "setting a property that has only a getter"

And if I try class instead of style, it doesn't like me using the word class in the javascript.
Sane is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:39 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC