如何选择父母的父类?
JS
<div onclick="$('.al_head.tt_this).closest('.aledmsg').remove();" style="cursor:pointer;"> TEST </div>
HTML
<div id="albox">
<div class="al_head" style="margin-bottom: 5px;" id="alss"> <img src="bt.png" alt="se">
<div style="float: left; width: 282px;" class="aledmsg"><strong>Feexts</strong>
<hr>
<div class="ams" id="xc98f">blub</div>
<div class="ams tt_this" id="xb697">blib <-</div>
<div class="ams" id="x56b1">blab</div>
<div class="ams tt_this" id="xb214">blnb <-</div>
<div class="ams tt_this" id="xb997">blmb <-</div>
</div>
</div>
<br /> <br />
<div class="al_head_2" style="margin-bottom: 5px;" id="alss"> <img src="bt.png" alt="se">
<div style="float: left; width: 282px;" class="aledmsg_2"><strong>Feexts 2</strong>
<hr>
<div class="ams" id="xc98f">blub</div>
<div class="ams tt_this" id="xb697">blib <-</div>
<div class="ams" id="x56b1">blab</div>
<div class="ams tt_this" id="xb214">blnb <-</div>
<div class="ams tt_this" id="xb997">blmb <-</div>
</div>
</div>
</div>
答案 0 :(得分:1)
我认为这就是你所追求的:
$('#albox .tt_this').closest('.aledmsg').remove();
You can give it a try here,引号在初始选择器上不匹配且.tt_this
类在子级上,而不是直接在#albox
<div>
上。