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

11-11-2009, 12:44 PM

currently I'm using:

$("a#test").live("click",function() {
$(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.


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.



$(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