Hi,
i think this is a short way to do it, altough i haven't tested it myself.
$("a.showHide").click(function() { $("#" + $(this).attr('rel')).toggle(); }); It uses the rel attribute of the anchor to find the DIV-Node, and using the toggle method, the div is either hidden or displayed, depending on the current status. cheers lukas Am 21.11.2008 um 00:56 schrieb Brendan:
I am new to jQuery (coming from Mootools) and the way things are done here are a bit different, but I am willing to put a lot of effort into learning it. That said, I have some working code here (I wrap it in the $ (document).ready function) but I wanted to know if there is a more efficient way to do it using jQuery's built in functions/selectors. I am flexible about how it is achieved, but I just need to know how I should "think" with jQuery. $("a.showHide").click(function(){ var aRel = $(this).attr("rel"); var dTog = $("div.showHide[id="+aRel+"]"); if(dTog.css('display') == 'block') { dTog.css('display','none'); } else { dTog.css('display','block'); } return false; }); a basic HTML example of this is: <a href="#" class="showHide" rel="test">click me</a> <div class="showHide" id="test">hide me</div> You can test it yourself, but it just shows or hides the div when the anchor is clicked. The div ID corresponds to the anchor's REL attribute. So in short-- is there a better way?