Getting first visible element with jQuery -
trying first visible element of list using jquery's :first
, :visible
pseudo-selectors, suggested here: https://stackoverflow.com/a/830611/165673 it's not working:
fiddle: http://jsfiddle.net/fay9q/4/
html:
<ul> <li>item a</li> <li>item b</li> <li>item c</li> </ul> <ul> <li style="display:none;">item a</li> <li>item b</li> <li>item c</li> </ul>
jquery:
$('li:visible:first').css('background','blue');
the first item in each list should turn blue...
try using this:
$('ul').find('li:visible:first').css('background','blue');
currently code getting first visible li
element on page , setting background colour. code selects ul
elements finds first visible li
within each of them , applies style.
here working: http://jsfiddle.net/fay9q/5/
Comments
Post a Comment