Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting styles of elements via ClassName

Status
Not open for further replies.

bdichiara

Programmer
Oct 11, 2006
206
US
I am using moo.fx Accordion and trying to make an alteration to the way it works and need some help.

I need to set all items in this array:
var myStretcher =
Code:
document.getElementsByClassName('accordian');

to this style:
Code:
display: 'block';
overflow: 'hidden';
visibility: 'hidden';
height: '0px';
filter: 'alpha(opacity=0)';
opacity: '0';
outline-color: invert;
outline-style: none;
outline-width: medium;
-moz-background-clip: -moz-initial;
-moz-background-origin: -moz-initial;
-moz-background-inline-policy: -moz-initial;
so far, i have:
Code:
for(i=0;i<=myStretcher.length;i++){
  myStretcher[i].style.display = 'block';
  myStretcher[i].style.filter = 'alpha(opacity=0)';
  myStretcher[i].style.opacity = '0';
}

What is the proper way to set all these styles? Am I even doing [what little I am doing] right?

Anybody with knowledge of this script would be extremely helpful.

Here's the site:
_______________
_brian.
 
Why not just make a new class with all those styles and set all elements of class acordian to the new class?

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
ok, I tried that, but I get an error:
Error: myStretcher has no properties

Code:
var myStretcher = document.getElementsByClassName('accordion');
for(i=0;i<=myStretcher.length;i++){
  myStretcher[i].className = 'accordion2';
}
myStretcher = document.getElementsByClassName('accordion2');

_______________
_brian.
 
Sorry, I can't really tell you what to expect. getElementsByClassName is not a core javascript method. I don't use moo.fx or prototype or script.aculous or any other plug-ins, and as such I don't know what their methods are returning. I'd like to think that getElementsByClassName returns an array of elements with the class name that you supply, but what happens when it returns 0 elements? Does the array still exist? Does it return false? Does it return an empty string? Does it return 0?

If I had to take a stab in the dark I'd say that's your problem - the method is not finding any elements. And as such, I can't tell you what to expect from the method when it finds nothing because it's not a core javascript method.

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
Ok, well, I put an Alert before and after the line:

myStretcher.className = 'accordion2';

That told me the className, and it told me, after changing each one, the old, and then the new className.

I think you might be onto something, because I put:

alert(myStretcher.length);

before my loop and it said "6", but then I tried:

var newStretcher = document.getElementsByClassName('accordion2');
alert(newStretcher.length);

And there wasn't even an alert. So apparently there is a bug with that method, in which case it brings be back to the beginning: is it possible to set all those styles to those elements in the original array?

_______________
_brian.
 
ok, I think i got this issue resolved. There was some other code that was specific to Accordion, so thanks for the help.

_______________
_brian.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top