1

Ok I have this code

 $("#search-results-all").children(".search-result-item").length;

Now, all I want there is to select only the .search-result-item elements that is only visible by using css attribute visibility:visible. Now how can i make this possible?

P.S. Sorry I don't know what to type in Google so I can start searching.

UPDATE...

well it worked by doing something like this

$("#search-results-all").children(".search-result-item:visible").length;

thank you for the answers

0

3 Answers 3

2

The following?

$("#search-results-all > .search-result-item").filter(function() {
   return $(this).css('visibility') == 'visible';
}).length;

http://api.jquery.com/filter/

Sign up to request clarification or add additional context in comments.

Comments

2

Try this one:

$("#search-results-all .search-result-item").filter(function() {
  return $(this).css('visibility') == 'visible';
});

Comments

1

:visible Selector - Selects all elements that are visible.

$("#search-results-all").children(".search-result-item:visible").length; 

or

$("#search-results-all").children(".search-result-item")).is(':visible'); 

3 Comments

I almost got this in the internet before i saw your answer.. thank you... this is correct and more clean
is returns a boolean, so I don't think you can use .length to it api.jquery.com/is
"Elements with visibility: hidden or opacity: 0 are considered visible, since they still consume space in the layout." - Basically, this completely fails to handle the situation the OP is asking about...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.