jQuery:隐藏父< td>如果包含子< input>与特定的班级? [英] jQuery: Hide parent <td> if contains child <input> with specific class?

查看:117
本文介绍了jQuery:隐藏父< td>如果包含子< input>与特定的班级?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery Tablesorter Filters插件,并且试图隐藏某些<td>.这就是我想要做的:

I'm working with the jQuery Tablesorter Filters plugin and I'm trying to hide certain <td>. This is what I'm looking to do:

-如果<td>包含<input class="tablesorter-filter disabled">,则隐藏父级<td>

-If <td> contains <input class="tablesorter-filter disabled">, hide the parent <td>

<tr class="tablesorter-filter-row">
    <td>
        <input class="tablesorter-filter">
    </td>

    <td>
        <input class="tablesorter-filter disabled">
    </td>

    <td>
        <input class="tablesorter-filter">
    </td>
</tr>

<script>
    jQuery(function ($) {
        $(".tablesorter-filter-row td").filter(function(i) { return $(this).find("> input.disabled").length > 0 }).hide();
    });
</script>

那是我从另一个问题中剔除的jQuery,但在这种情况下它没有隐藏父td.

That is the jQuery I culled from another issue I had, but it's not hiding the parent td in this instance.

推荐答案

您的代码看起来不错.确保您在 DOM就绪处理程序中执行此操作,并且它应该可以正常运行.

Your code look fine. Make sure you do this in DOM ready handler and it should work fine.

$(function() {
   $(".tablesorter-filter-row td").filter(function() {
         return $('input', this).hasClass('disabled');
    }).hide();
});

检查小提琴

Check Fiddle

这篇关于jQuery:隐藏父&lt; td&gt;如果包含子&lt; input&gt;与特定的班级?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆