html - how to toggle particular field with same id or class? -
the 'comment' field has 'id' , 'class', can't give unique 'id' because coming database (dynamic output). have tried 'toggle' (hide , show) jquery, when click particular 'comment' field of form (textarea) appearing (toggling). how toggle particular field same id or class?
$(".commentform").hide(); $(".askforcomment").click(function(){ $(".commentform").toggle(); }); <div id='comments'> <div id='askforcomment' class='askforcomment'>comments?</div> <div id='viewcomments'></div> <form id='commentform' class='commentform'> <textarea cols='20' rows='2'></textarea> <input type='button'> </form> </div><!-- element looped (dynamic) -->
you should target specific .commentform
here :
$(".askforcomment").click(function(){ $(this).siblings(".commentform").toggle(); });
this toggle .commentform
near askforcomment
. or, :
$(".askforcomment").click(function(){ $(this).parent().find(".commentform").toggle(); });
hope helps!
Comments
Post a Comment