...

View Full Version : Resolved click anchor, display relevant <div>



met
11-11-2009, 12:44 PM
hi

currently I'm using:



$("a#test").live("click",function() {
$('div#test').toggle("fast");
$(this).css("border-bottom", "1px solid #813563")

});




<a href="#" class="test">Show Test</a>
<div id="test">Test..</div>


when I click the link, test div shows.

I'd like to have 4-5 links on the page, that, when clicked, show content for the appropriate div.

I was intending to copy and paste the above code and adjust the ID each time, but this seems so inelegant

is there a better way to achieve this? Assuming each link and its div share an ID or class.

so:

test1 link > show test1 div
test2 link > show test2 div

i'd also like to hide every other div, so only one is on display at a given time.

hope this makes sense, thanks.








resolved

http://stackoverflow.com/questions/1657099/on-jquery-with-a-lot-of-items-show-only-div-of-this-anchor-clicked/1657171#1657171



$(document).ready(function() {
$('.item > p > a').click(function(){
$('#details > div').hide(); // hide all of the divs
$('div.' + this.id).show("slow"); // then show the one with the
//same class as the link.id that was clicked
});
});



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum