View Full Version : Set style

Aug 3rd, 2007, 02:05 AM
There is an eliment on the page with the class of "abc" , and what i need to do is set a style property to it , how would i do it... I more/less need to go , getElimentByClass of abc , with style = "embed, object {display:none}"

Aug 3rd, 2007, 02:21 AM
Unfortunately, there isn't a 'getElementsByClassName'.

For a single element you would not need to worry about the class

document.getElementById('elementID').style.display = 'none';

For more than one element, dealing with class, the work around is to
get the list of elements, then loop through them.

function chgClassStyle(ele) {
var n, elist = document.getElementsByTagName(ele); // li div p * etc
for (n=0;n<blist.length;n++) {
if (elist[n].className == 'abc') elist[n].style.display = 'none';

call with


Aug 3rd, 2007, 03:04 AM
It is only one eliment , HOWEVER it doesnt have an ID , it only has a class, and i dont want to set that whole element to none, i just want to set the element style to embed,object {display:none} (which hides all the flash in that element)

Aug 3rd, 2007, 03:58 AM
Can you wrap the flash in a division and hide it?
You get get the object and embed at the same time?

To get the first or only object and embed without class info:


Since the embed is a child of the object, you may just need to hide it, haven't tried

The loop method checking the class would work too

Aug 3rd, 2007, 05:35 AM
The only problem with THAT is it hides only the first embed and object on the WHOLE page, i only need it to hide embed,object on one class name (which is abc)

Is there a way to load a custom style sheet with javascript ?

Aug 3rd, 2007, 05:43 AM
No, [0] just applies the style to the first object element and first embed element. [1] would be the second, [2] the third and so on

Use the loop

Aug 3rd, 2007, 05:56 AM
eh.. the number of objects vary.. is there a way i can load a custom style sheet with javascript ?

Aug 3rd, 2007, 06:21 AM
var createLink = document.createElement('link');