tags:

views:

30

answers:

5

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></tr>
<tr></td></td></tr>
<tr style="display:none" class="test"></td></td></tr>>
<tr></td></td></tr>

Thanks

A: 
$(document).load(function() {
    $('.test').hide();
});
Michael Pardo
$(function() {}) is equivalent to $(document).load(function {})
Matt Briggs
I actually use $(function() {}), but a lot of jQuery noobs don't know that syntax, so I used the more verbose syntax.
Michael Pardo
+3  A: 

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');
Pointy
+1, but should be `$('tr:hidden').addClass('test');`
Mark B
i love how jquery makes you better at css :-)
Matt Briggs
$('tr:hidden').addClass('test');
Michael Pardo
A: 

or if you wanna alter its style .. use

$(function() {
    $('.test').css("display", "none");
});
c0mrade
+2  A: 
$("tr").each(function(){
  if($(this).css("display") == "none")
      $(this).addClass("test");
});
brendan
The only one who answered the question +1
Naeem Sarfraz
+2  A: 

You could do:

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

or

$(".test:hidden")

or (most accurate to your question)

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