jQuery Previous DIV Class -
i' using jquery previous div class "our-partner-readmore". have tried alot not possible in doing it.
html
<div class="our-partner-readmore"><a class="accordion-toggle btn-readmore collapsed" data-toggle="collapse" data-parent="#accordion2" href="#collapse2"></a></div> <div class="our-partner-readmore"><a class="accordion-toggle btn-readmore collapsed" data-toggle="collapse" data-parent="#accordion2" href="#collapse2"></a></div>
js
$('a.btn-readmore').on("click", function(){ var is_collapsed = $(this).hasclass("collapsed"); alert(is_collapsed); if(is_collapsed){ $(this).prev('.our-partner-readmore').addclass("none"); $(this).next('.our-partner-readmore-closed').removeclass("none"); } else { $(this).prev('.our-partner-readmore-closed').addclass("none"); $(this).next('.our-partner-readmore').removeclass("none"); } });
more explaination
whenever clicks on "a.btn-readmore", using jquery trying previous div class "our-partner-readmore" dynamically.
thanks guys
your issue might solved using jquery parent function. here api detail.
$(this).parent(); //will give parent
Comments
Post a Comment