<li><a href="http://www.yahoo.com " target="_blank"> goto yahoo.</a>
<span id="comment"><img src="https://dl.dropboxusercontent.com/u/26715029/img/fc.jpg" style="vertical-align:middle" width="20" height="20" alt="fc"/>| or comment about yahoo</span>
<div class="commentbox">
<div id="fb-root">coment box is here</div>
</div>
</li>
<li><a href="http://www.google.com " target="_blank"> go to google </a>
<span id="comment"><img src="https://dl.dropboxusercontent.com/u/26715029/img/fc.jpg" style="vertical-align:middle" width="20" height="20" alt="fc"/>or comment about google</span>
<div class="commentbox">
</div>
</li>
Need to toggle specific li div, not both. Tried accordion but link does not work. FYI: The list is much larger http://jsfiddle.net/NQw5L/18/
IDs must be unique. If you convert them to a class, you can use:
$(document).ready(function () {
$('.comment').click(function () {
$(this).next('.commentbox').slideToggle("slow");
});
});
j08691 is right, but if you dont want to do that manually - try setting the class instead of the id and using this:
$(document).ready(function() {
var cCtr=0;
$('.commentbox').each (function() {
$(this).attr('id','comment'+cCtr++);
});
var cCtr=0;
$('.comment').each (function() {
$(this).attr('data-targ', 'comment'+cCtr++);
});
$('.comment').click(function() {
var slId = $(this).attr('data-targ');
$('#'+slId).slideToggle("slow");
});
});
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.