在表单元格 jQuery 中选择 div



我需要选择深埋的div,类为"srch-maintop",上下文为最顶层的div"srch-sb-results"。如何使用 jquery 选择 srch-maintopdiv?

我甚至接近这里吗?

$('.srch-sb-results').next('table').find('td#MainLeftCell div.srch-maintop').delete();  

那甚至没有碰到它..

<div class="srch-sb-results"> stuff here </div>
    <table>
       <tr>
          <td colspan='3'>
             <div style="border:1px solid silver"></div>
           </td>
         </tr>
         <tr>
             <td class="srch-leftcell">stuff</td>
            <td class="srch-mainleftcell">
               <div>stuff</div>
               <div class="srch-maintop"></div>
               <div class="srch-maintop2"></div>
            </td>
            <td class="srch-rightcell">stuff</td>
         </tr>
    <table>

改用 remove():

$('.srch-sb-results').next('table').find('td#MainLeftCell div.srch-maintop').remove(); 

并且没有classid命名为MainLeftCell.

我认为

问题是你把#MainLeftCell写成ID的,但你必须把它写成.MainLeftCell。是的...您可以使用.remove()代替.delete()

是的,你很接近;)

$('.srch-sb-results').next('table').find('td.srch-mainleftcell div.srch-maintop').delete();

如果给定类没有其他元素,您可以单独使用它:

$('.srch-maintop').remove();

或者在带有类 'srch-sb-results' 的div 旁边的表格中找到更具体的一个:

$('.srch-sb-results').next('table').find('.srch-maintop').remove();

最新更新