Reputation: 11458
Given the following code
var a = $('<div><div></div></div>');
a.css("visibility", "visible");
a.find("* :visible");
I receive an empty array []
as a result instead of a div
. What am I doing wrong?
Upvotes: 2
Views: 86
Reputation: 337626
To check if an element is visible, it must be inserted into the DOM. You also don't need the *
selector. Try this:
var a = $('<div><div></div></div>'); // create an element
a.css("visibility", "visible");
$("BODY").append(a) // Add the element to the DOM first
a.find(":visible")
alert(a.find(":visible").length); // displays '1'
Upvotes: 3
Reputation: 700562
You haven't added the element to the page, so it's not sized yet. Elements with zero size are not considered visible.
Upvotes: 1