jQuery - How do I select div inside same table cell?
I am trying to select a div that is inside the same tr as the href link. I have several other divs in o开发者_如何学Cther table rows that share the same class. I can't use parent(); or find();, can I?
<tr><td>
<a href="#" class="downloadTracksShow">Download Tracks</a><div class="downloadTracksDiv" style="display:none;">
<a href="downloads/mike/166320669010secreason.wav">Main Mix Track</a><br>
<a href="downloads/mike/94964secreason.wav">Bass</a><br></td></tr>
</div>
$('.downloadTracksShow').click(function(e){
e.preventDefault();
var tracksDiv = $(this).find(".downloadTracksDiv");
$(tracksDiv).slideToggle();
});
$('.downloadTracksShow').click(function(e){
e.preventDefault();
$(this).next().slideToggle();
return false;
});
Give this a shot
$('.downloadTracksShow').click(function(e){
e.preventDefault();
$(this).siblings("div.downloadTracksDiv").slideToggle();
});
精彩评论