whenever click comment link of divs opening need particular opened.
html:
<div> <a href="#" class="ck">comment</a> <div class="cmt"> <input type="text" class="txt"/> <input type="button" value="submit"/> </div></div> <div> <a href="#" class="ck">comment</a> <div class="cmt"> <input type="text" class="txt"> <input type="button" value="submit"> </div></div> <div> <a href="#" class="ck">comment</a> <div class="cmt"> <input type="text" class="txt"/> <input type="button" value="submit"/> </div></div> <div> <a href="#" class="ck">comment</a> <div class="cmt"> <input type="text" class="txt"/> <input type="button" value="submit"/> </div></div> jquery:
$(document).ready(function(){ $(".cmt").hide(); $(".ck").click(function(){ $(".cmt").show(); }); }); jsfiddle: http://jsfiddle.net/48gfje0f/
you can use jquery nextall() , filter first matching element:
$(".cmt").hide(); $(".ck").click(function(){ $(this).nextall(".cmt:first").show(); }); demo: http://jsfiddle.net/48gfje0f/3/
also, instead of using show() use toggle(), show , hide relevant div when click on link.
Comments
Post a Comment