How to select every last child which got specific css property?

drcula112

New Member
I am trying to select every last element which got \[code\]display:block\[/code\] properties in a hidden parent element.Here is an example fiddle to play with.html:\[code\]<ul style="display:none;"> <li>1</li> <li>2</li> <li>3</li> <li style="display:none;">4</li></ul>\[/code\]jQuery:\[code\]$('ul').each(function() { visibleCount =+ 0; $(this).children('li').each(function(index) { if ( $(this).css('display') === 'block' ) { visibleCount += 1; $(this).html(index); //can't find the right formula //if ( index === (visibleCount-1) ) { //$(this).addClass('last-visible'); //} } });});$('ul').find('li:visible:last').addClass('last-visible');//This won't effect on child elements while their parent is hidden.\[/code\]I found this similar question but solution works on visible parent.
 
Back
Top