I'm trying to create a JS function that will change the name of a CSS class.
It's working in IE8, and although IE6 does pick up the name change it DOES NOT seem to apply the actual changes. It's driving me crazy.
Here's my JS function:
The above will detect if the side menu is showing (dV == 'block') and adjust the css class accordingly. I need to use class names instead of individual style attributes, since I want the same class in the main stylesheet to show one width, and a different width when the print stylesheet is used for displaying the same class and HTML.Code:function resizeContent() { var c = document.getElementById('content'); var dV; if (window.getComputedStyle) { dV = window.getComputedStyle(e,null).getPropertyValue('display'); // CSS 2 Method } else if (e.currentStyle) { dV = eval('e.currentStyle.display'); //IE's method } if( dV == "block" ) { c.setAttribute('class','withnav'); c.setAttribute('className','withnav'); c.className = 'withnav'; alert('set to class ' + c.getAttribute('class') + ' and classname ' + c.getAttribute('className')); } else { c.setAttribute('class','nonav'); c.setAttribute('className','nonav'); c.className = 'nonav'; alert('set to class ' + c.getAttribute('class') + ' and classname ' + c.getAttribute('className')); } }
It seems to be working, in that my test alerts display the correct class names, but in IE6 the 'nonav' class doesn't actually get applied so you can't see the changes. withnav is displayed by default.
My HTML is very straightforward.
<a href="javascript:toggleDisplay('rhNav'),resizeContent();"><img src="/images/hdr_ico_toggle.gif" alt="Toggle the display of the right hand navigation bar" width="11" height="16" border="0"> Toggle Navigation Bar</a>
<div id="content" class="withnav">
...
</div>
is displayed initially with the class name changing dynamically.
I've been googling this for several hours with no luck. Anyone have any ideas?



Reply With Quote


Bookmarks