Use each():
var displays = '';
$("p").each(function(i, val) {
displays += "Paragraph " + i + ": " + $(this).css("display") + "\n";
});
alert(displays);
The reason this fails:
var target = $("p");
var display = target[0].css("display");
is that target[0]it is not a jQuery object. You can do it:
var display = $(target[0]).css("display");
Also, if you read the documentation for css():
Returns a style property on the first matched element.
Two other issues worth mentioning.
Firstly, I would not recommend doing the hint myself. Get one of many plugins for this. I previously used this and did this work.
Secondly, if you are checking CSS display values, it might be useful to use a shortcut. For example, you can do this:
$("p").each(function() {
if ($(this).css("display") == "none") {
$(this).addClass("blah");
}
});
:hidden :visible, :
$("p:hidden").addClass("blah");
css() , , .