[英]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. 我正在尝试选择与href链接位于同一tr内的div。 I have several other divs in other table rows that share the same class.
我在其他共享相同类的表行中还有其他一些div。 I can't use parent();
我不能使用parent(); or find();, can I?
或find();,可以吗?
<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();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.