views:

46

answers:

2

hi guys, i have

<ul>
<li class="section-title">HEADER which triggers dropdown</li>
   <li><a href="element_one">element one</a></li>
   <li><a href="element_one">element one</a></li>
   <li><a href="element_one">element one</a></li>
</ul>

i'm hiding all li-elements (except the first one) with this line:

$('#menu ul li.section-title:first-child').parent().children('li').hide();

i wonder if it's possible to query if one of those three links is active and if so nothing should hide!

is that even possible? thank you for your help!

A: 

Why not attach a class to the active link, then you could do something like:

$(document).ready(function() { $(".myClass").doSomething();});
gnome
if i click a link the page gets refreshed! if i attach a class when i click a link (so it's the active link) the page gets refreshed and the class is gone!
That's a server side question, really. Although you could try to deduce the clicked link from the url ... however, that's a rather foolish thing to do, it's much easier to just output a class server-side. If you are at all in control of the output, that is.
Fake51
maybe i could write a cookie somehow and query what link got clicked last? i know theres a jquery cookie plugin! i just wondered if it's possible to query if a link is active!?!
Do it server-side as Fake51 said. Creating a cookie to track a link is a bit much.
Kerry
A: 
  1. Your code will actually hide all li elements (including the first one).
    Use $('#menu ul li:not(:first-child)').hide(); to hide all but the first one..
  2. For the next part (to only hide them if none is the current one) use

    var loc = window.location;
    var anyActive = false;
    $('#menu li a').each(function(){
        anyActive = anyActive || (this.href == loc);
    });
    
    
    if (!anyActive)
        $('#menu ul li:not(:first-child)').hide();
    

Update with working code, after comment

var loc = window.location;

$('#menu li a').each(function(){
    if (this.href == loc)
        $(this).addClass('activelink');
});

$('#menu ul:not(:has(.activelink)) li:not(:first-child)').hide();

live example: http://www.jsfiddle.net/SMmtS/3/

Gaby
thank you, the only problem is that anyActive returns true if a link is active. however i have a few of those ul-navigatin elements side by side and only the one with the active link in it should show, not all of them!
@mathiregister, updated answer with new solution for this..
Gaby