so here is the code i use this for me to show/hide the comment box it works actually but the problem i encounter when i make multiple comments when i tried to click the reply on the 1st comment the comment box show/hide but when i tried to click other comments it doesnt work anymore it only works on the first one.... is there any way to fix this?..
HTML code
<div id="replybutton" class="btn4 like" style="margin-top:-25px;margin-left:-10px;">
<span class="btn reply" id="replyb">Reply</span> • 
</div>
<div class="col-lg-12" id="reply" style="background:#eff9c7;margin-left:50px;margin-top:-20px;display:none;" >
<img src="img/icons/no-icon-available.png" class="pull-left" style=" border-radius:50%;margin-bottom:3px;width:30px;height:30px;" />
<p style="margin-top:18px;line-height:15px;"><strong class="font-1" style="margin-left:10px;">Hajime Sasota </strong> Sample comment<br>
<div class="btn4 disabled" style="margin-top:-25px;margin-left:-10px;">
<span style="margin-left:5px;font-size:12px;color:gray;"><abbr class="timeago" title="">time</abbr></span>
</div>
</p>
<input type="text" class="form-control pull-right" style="width:88%;height:25px;margin-top:-10px;" placeholder="Write a reply..." />
</div>
JAVASCRIPT
<script type="text/javascript">
$(document).ready(function(){
$('#replybutton').click(function(){
$('#reply').toggle();
});
});
</script>
id
must be unique in a HTML Page, you should change id to class replybutton
and reply
and jquery code would be,
$(document).ready(function(){
$('.replybutton').click(function(){
$(this).next('.reply').toggle();
});
});
Snippet,
$(document).ready(function() { $('.replybutton').click(function() { $(this).next('.reply').toggle(); }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <div class="container"> <div class="replybutton btn4 like" style=""> <span class="btn reply" id="replyb">Reply</span> •  </div> <div class="col-lg-12 reply" style="display:none"> <img src="img/icons/no-icon-available.png" class="pull-left" style="" /> <p> <strong class="font-1" style="margin-left:10px;">Hajime Sasota </strong> Sample comment<br/> <div class="btn4" style=""> <span style=""><abbr class="timeago" title="">time</abbr></span> </div> </p> <input type="text" class="form-control pull-right" placeholder="Write a reply..." /> </div> </div> <div class="container"> <div class="replybutton btn4 like" style=""> <span class="btn reply" id="replyb">Reply</span> •  </div> <div class="col-lg-12 reply" style="display:none"> <img src="img/icons/no-icon-available.png" class="pull-left" style="" /> <p> <strong class="font-1" style="margin-left:10px;">Hajime Sasota </strong> Sample comment<br/> <div class="btn4" style=""> <span style=""><abbr class="timeago" title="">time</abbr></span> </div> </p> <input type="text" class="form-control pull-right" placeholder="Write a reply..." /> </div> </div> <div class="container"> <div class="replybutton btn4 like" style=""> <span class="btn reply" id="replyb">Reply</span> •  </div> <div class="col-lg-12 reply" style="display:none"> <img src="img/icons/no-icon-available.png" class="pull-left" style="" /> <p> <strong class="font-1" style="margin-left:10px;">Hajime Sasota </strong> Sample comment<br/> <div class="btn4" style=""> <span style=""><abbr class="timeago" title="">time</abbr></span> </div> </p> <input type="text" class="form-control pull-right" placeholder="Write a reply..." /> </div> </div>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.