error77
asked on
Javascript script getElementsByClassName issue
Hi all,
I am trying the following:
var myDiv = document.getElementsByClas sName('myC lass');
alert(myDiv);
This is returning: [object HTMLCollection]
I need to change all the width's of a class on my page...
myDiv.style.width = swidth + 'px';
It works on getElementById but not in Classes ... how can I get this to work please?
THanks
I am trying the following:
var myDiv = document.getElementsByClas
alert(myDiv);
This is returning: [object HTMLCollection]
I need to change all the width's of a class on my page...
myDiv.style.width = swidth + 'px';
It works on getElementById but not in Classes ... how can I get this to work please?
THanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you need to use getElementsByClassName on IE : http://robertnyman.com/2008/05/27/the-ultimate-getelementsbyclassname-anno-2008/
Else with jQuery :
Else with jQuery :
$(".myClass").css({"width":swidth + 'px'});
ASKER
Perfect thanks :)
// untested
var i = -1;
while ( ++i != myDiv.length ) {
myDiv[ i ].style.width = "1px";
}