I'm a bit stuck here with my script:
Its a checkbox filtering all .notme
images and hiding it's list items. The problem is now I cant get a working callback function for the fadeToggle
. It should behave like this :
If all children of
#list-team-single-container
are "displayed none" - do something.
$('#show-only-my-teams').change(function(){ $('.notme').each(function(){ $(this).parent().parent().fadeToggle('fast', function(){ }); }); });
You can use the jQuery :visible selector to check whether an element is visible in the layout or not. This selector will also select the elements with visibility: hidden; or opacity: 0; , because they preserve space in the layout even they are not visible to the eye.
Another way to check if an element is hidden is to use the window. getComputedStyle() method. It will return the display property value of the object. We can check if the string is equal to none meaning the element is hidden and do something.
If You want to get list only children elements with id or class, avoiding elements without id/class, You can use document. getElementById('container'). querySelectorAll('[id],[class]'); ... querySelectorAll('[id],[class]') will "grab" only elements with id and/or class.
We can do the following to check an element's visibility in the viewport: Get the bounding rect of the DOM element using the getBoundingClientRect . This method returns an object with an element's width, height, and position relative to the viewport.
if($('#list-team-single-container').children(':visible').length == 0) { // action when all are hidden }
The :visible
jQuery selector might be what you are looking for...
From the description
Elements are considered visible if they consume space in the document. Visible elements have a width or height that is greater than zero.
Elements with visibility: hidden or opacity: 0 are considered visible, since they still consume space in the layout. During animations that hide an element, the element is considered to be visible until the end of the animation. During animations to show an element, the element is considered to be visible at the start at the animation.
http://api.jquery.com/visible-selector/
$('#list-team-single-container').children(':visible');
That line of code will return all of the child elements of #list-team-single-container
that are visible.
$('#list-team-single-container').children(':visible').length;
That line of code will return the number of child elements of #list-team-single-container
that are visible.
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