accordion - Remove class from all <a>-tags within a certain div using jQuery -
i'm using jquery , have managed paste simple accordion can have 1 section of accordion open @ same time. each section of accordion has subitems has "+"-sign indicate this. when section clicked , content expanded, "+"-icon switches "-". this works fine , dandy until need have 2 (or more) accordions on same page. way works now, script switches expanded divs "-"-icons "-" "+". want +/- icons within same div latest clicked link switch, way now, icons of expanded sections changed when link clicked.
here script used:
$(document).ready(function() { $(".accordion dd").hide(); $(".accordion dt a").click(function(){ $(this).parent().next().siblings("dd:visible").slideup("slow"); $(this).parent().next().slidetoggle("slow"); if ($(this).is("expanded")) { $(this).toggleclass("expanded"); } else { $(".accordion dt a").removeclass("expanded"); $(this).addclass("expanded"); } return false; }); }); here html. html below 1 instance. if there more 1 list on page, html structure below duplicated.
<div style="position:relative;" class="regularborder roundedcorner"> <h2>header</h2> <dl class="accordion"> <dt class="roundedcorner navbarbg first nosideborder"> <a href="/">lorem ipsum 1</a></dt> <dd> <ul class="accordion nosideborder"> <li><a href="#">lorem ipsum dolor</a></li> <li><a href="#">lorem ipsum dolor</a></li> </ul> </dd> <dt class="roundedcorner navbarbg nosideborder"> <a href="/">lorem ipsum 2</a></dt> <dd> <ul class="accordion nosideborder"> <li><a href="#">lorem ipsum dolor</a></li> <li><a href="#">lorem ipsum dolor</a></li> </ul> </dd> <dt class="roundedcorner navbarbg nosideborder"> <a href="/">lorem ipsum 3</a></dt> <dd> <ul class="accordion nosideborder"> <li><a href="#">lorem ipsum dolor</a></li> <li><a href="#">lorem ipsum dolor</a></li> </ul> </dd> </dl> </div> so simple solution making work appreciated!
shouldn't this:
$(".accordion dt a").removeclass("expanded"); be this:
$(this).parents('.accordion').find('dt a').removeclass("expanded");
Comments
Post a Comment