Maanstraat
Maanstraat

Reputation: 1251

jQuery show hide multiple links

I have 3 show more links in my layout. They must trigger all the same table with content. So when you click on link 1 it shows the table, but if you click on link 2 the table won't be hidden again (only when I click 2 times).

How can I fix this?

My code I have now:

$(".starterlink").toggle(
    function(){ $(".starterinfo").fadeIn('fast'); }, 
    function(){ $(".starterinfo").fadeOut('fast'); }
);

Upvotes: 1

Views: 304

Answers (3)

Chris Snowden
Chris Snowden

Reputation: 5002

If I understand your question correctly, why don't you do something like:

$(".starterlink").click( function(){ $(".starterinfo").fadeToggle('fast'); } );

Updated:

The following test code works fine for me.

<a href="#" class="starterlink">Click me</a>
<div class="starterinfo">This will fade in and out</div>

<script type="text/javascript">
    $(".starterlink").click(function () { $(".starterinfo").fadeToggle('fast'); });
</script>

Upvotes: 4

Rob
Rob

Reputation: 3066

Maybe something like

$("#link1").click(function(){
    $("#tableid").attr('visible', false);
});

$("#link2").click(function(){
    $("#tableid").attr('visible', true);
});

Upvotes: 0

MeLight
MeLight

Reputation: 5565

toggle() function has no toggle(function, function) signature. IE it doesn't take two functions as arguments.

Upvotes: 1

Related Questions