PDA

View Full Version : Dynamically changing the display value of a classname


Skyzyx
03-22-2003, 05:09 AM
I am working on a "Dreck Filter" for my new website. A "Dreck Filter" is basically a way for the user to choose whether or not to read personal content along with professional content. It is the same idea as http://www.youngpup.net/classic.asp

It works as expected in Moz and Opera, but it doesn't seem to work in IE6.


<form action="javascript:void(0);" name="dreckform" id="dreckform">
<select name="dreck" id="dreck" style="font-size:8pt; border:1px solid #000000;" onchange="dreckChange();">
<option value="block">With Personal Dreck</option>
<option value="none">Without Personal Dreck</option>
</select>
</form>

. . . . . . .

function dreckChange()
{
var allDivs=document.getElementsByTagName('div');

var allDivsLen=allDivs.length;
var x;

for (x=0; x<allDivsLen; x++)
{
if (allDivs[x].getAttribute('class') == 'personalContent')
{
allDivs[x].style.display=document.getElementById('dreck').value;
document.getElementById('dreck').blur();
}
}
}



Always-On content has a classname of "content", while personal content has a classname of "personalContent". I'm only worried about the "personalContent" class.

The live example can be seen at http://host44.ipowerweb.com/~skyzyxco/news/

I'd appreciate any help, otherwise I'll have to leave IE behind.

Graeme Hackston
03-22-2003, 08:08 AM
try this

if (allDivs[x].className.match('personalContent')) {

Weirdan
03-22-2003, 10:02 AM
From MSDN Library (getAttribute method):
--
When retrieving the CLASS attribute using this method, set the sAttrName to be "className", which is the corresponding Dynamic HTML (DHTML) property.
--
It works.