Toggle need to click twice
so i basically have many anchor links where when i click each of them it slidesdown its own div with some text in it...
so have i wanted is when i click on one link it will show me the current one and hide the others..
this is what i have tried which works great but when i click on a link it opens the div , then click on another one opens the div with one click and when i go back to re-click the previous link i have to double click it in order to work..
this is my js code:
- $(".anchorlink").toggle(
function() {
var cont_val = $(this).attr("id");
$("div#unique_anchor_text", this).show();
$("div#unique_anchor_text").hide();
$('.unique_anchor_text'+cont_val).slideDown("fast");
},
function() {
var cont_val = $(this).attr("id");
$('.unique_anchor_text'+cont_val).hide();
}
);
html looks like:
- <a class='anchorlink' id='$item'>Comment</a>
- <div id='unique_anchor_text' class='unique_anchor_text$item'>some text</div>
thanks