开发者

jquery, selector, style

开发者 https://www.devze.com 2022-12-21 01:48 出处:网络
HI, How can I add by jQuery, some class \"test\" justtowhat have style=\"display:none\", Output: <tr style=\"display:none\" class=\"test\"></td></td&g开发者_如何学编程t;</tr>

HI,

How can I add by jQuery, some class "test" just to what have style="display:none",

Output:

<tr style="display:none" class="test"></td></td&g开发者_如何学编程t;</tr>
<tr></td></td></tr>
<tr style="display:none" class="test"></td></td></tr>>
<tr></td></td></tr>

Thanks


Well the ":hidden" qualifier is sort-of what you want:

$('div:hidden').addClass('test');

That's a little flaky because ":hidden" does not just apply to elements with an explicit "display:none" style. If you really want it to be robust, it would be better to give your hidden elements some other class name (even if it doesn't have any CSS effect). Then you could write:

$('div.testMe').addClass('test');


$("tr").each(function(){
  if($(this).css("display") == "none")
      $(this).addClass("test");
});


You could do:

$(".test[style*=none]")

or

$(".test:hidden")

or (most accurate to your question)

$(".test").filter(function() { return $(this).css('display') == 'none'; });


$(document).load(function() {
    $('.test').hide();
});


or if you wanna alter its style .. use

$(function() {
    $('.test').css("display", "none");
});
0

精彩评论

暂无评论...
验证码 换一张
取 消