Jquery - 父选择器(最近的)

时间:2010-09-22 11:09:51

标签: jquery

如何选择父母的父类?

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>

http://jsfiddle.net/RAN9C/9/

1 个答案:

答案 0 :(得分:1)

认为这就是你所追求的:

$('#albox .tt_this').closest('.aledmsg').remove();

You can give it a try here,引号在初始选择器上不匹配且.tt_this类在子级上,而不是直接在#albox <div>上。