tags:

views:

159

answers:

2

When an html element has the height and width set to zero, jQuery does not find the object when using a selector and specifying visible although the object is visible.

for example

$("#test").children(":visible")

the above will ignore children of #test where the width and height is zero. Is this an intended functionality or a bug in jQuery? Is there any workaround to get the object?

Many Thanks, Arun

PS: I'm using the latest version of jQuery - 1.3.2

+3  A: 

Not a bug in jQuery (in fact, the Sizzle Selector Engine that jQuery uses). From the jQuery source

Sizzle.selectors.filters.visible = function(elem){
    return elem.offsetWidth > 0 || elem.offsetHeight > 0;
};

Just implement your own filter with different logic. The filter is declared on line 2373 in the jQuery-1.3.2.js source file.

Russ Cam
+2  A: 

Yes this is the intended functionality. From the docs:

How :visible is calculated was changed in jQuery 1.3.2. Element assumed as visible if it and its parents consumes space in document. CSS visibility isn't taken into account.
http://docs.jquery.com/Selectors/visible

http://docs.jquery.com/Selectors/visible

PetersenDidIt