Jquery linking button to specific content -
i have concept similar of accordian. have button, when clicked, slides down div specific id. have around 3 of these on page. how write 1 function automatically chooses correct div slide down?
i've seen plugins use rel
attribute achieve this. in actual jquery code, how accomplish this?
eg code:
<a rel="#c1">slide 1</a> <a rel="#c2">slide 2</a> <div id="c1"></div> <div id="c2"></div>
you like
$("a").click(function() { var divselector = $(this).attr("rel"); $(divselector).slidedown(); });
if want bit more fancy, group items (or give them class) , following other containers slide up.
<div id="sliders"> <a rel="#c1">slide 1</a> <a rel="#c2">slide 2</a> </div> <div id="slidees"> <div id="c1"></div> <div id="c2"></div> </div> $("#sliders a").click(function() { var divselector = $(this).attr("rel"); $("#slidees div").not(divselector).slideup(); $(divselector).slidedown(); });
Comments
Post a Comment