Forum Moderators: open

Message Too Old, No Replies

Problem with css

Problem setting Css class with Java Script

         

The_chaval

3:25 pm on Aug 21, 2009 (gmt 0)

10+ Year Member



Here's the problem . I have a site that has a static header, and tabs in the header. I need to know which tab is active, but since the tabs are in the same header shown on every page, i cant change the class to active..
i have a javaScript method to achive that, but when the postback occurr(after postback) the element tabs clicked lost the Css("current") class and doesn't present the colors indicatives references to the actives tabs.

I show u the JavaScript function code:
function change(objElement) {
objElement.className = "current";
}
the following is the html that implements javascript function:

<ul id="saturday">
<li><a id = "index" href="index.aspx" onclick = change(this)><span>Inicio</span></a> </li>
<li><a href="Default.aspx " id = "contacto" onclick =change(this)><span>Contacto</span></a>
</li>
</ul>

So basically i need a way to switch the active class between the tabs depending on what tabs is clicked .
Anyone have any idea how to do it?

daveVk

12:07 am on Aug 22, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You need to do this either as part of the server asp processing, best option as will work with js disabled, or in js page onload function.

window.onload = function (){
var els = document.getElementsByTagName('A');
var el;
for ( var i=0; (el=els[i++]); ) {
if ( el.href === document.location.href ) ( el.className="current"; }
}
}

Welcome to forum.

The_chaval

5:49 pm on Aug 24, 2009 (gmt 0)

10+ Year Member



thanks.