javascript - jQuery show/hide for multiple elements without specific classes / id's -
i have following html , js code show / hide div. @ moment working fine. use more 1 box on page , need have function know box-header clicked.
is possible trigger box-content div after box-header div clicked? great if don't have use specific id's every box.
here code:
html:
<div class="content-box"> <div class="box-header open-close"> title </div> <div class="box-content"> content </div> </div>
js:
$(document).ready(function(){ $(".box-content").hide(); $(".open-close").click(function () { $(".box-content").slidetoggle("slow"); }); });
you can find box-content
element in relation clicked open-close
element.
from given markup, next element of clicked element
$(document).ready(function(){ $(".box-content").hide(); $(".open-close").click(function () { //as @insertusernamehere said selector ".box-content" not required //$(this).next(".box-content").slidetoggle("slow"); $(this).next().slidetoggle("slow"); }); });
demo: fiddle
Comments
Post a Comment