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.