I'm using the latest jquery version.(1.9.1)
I have an empty span element :
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body> <span class="c"></span>
</body>
<script type='text/javascript'>
alert($(".c:visible").length);
</script>
</html>
010 Why doesn't it alert1 at chrome ? the element is not hidden.
I can work around this by using filter and spit out all the !display:none but wanted to know if i'm doing anything wrong
http://jsbin.com/urihov/2/edit
@inser is right a span is an inline element and only gains layout when it has content thus gaining the width and height of its content - in this case the width and height are 0 so not visible to the, if you add this css rule
.c {
display: block;
}
you will see that the alert says 1 now since you have forced it to be a block element now thus inheriting the width of its parent and gaining layout.
hope it helps,
Cheers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With