Getting first visible element with jQuery

前端 未结 3 426
我寻月下人不归
我寻月下人不归 2021-01-03 22:43

Trying to get the first visible element of a list using jQuery\'s :first and :visible pseudo-selectors, as suggested here: https://stackoverflow.co

3条回答
  •  迷失自我
    2021-01-03 23:28

    Try using this:

    $('ul').find('li:visible:first').css('background','blue');
    

    Currently your code is just getting the first visible li element on the page and setting the background colour. This code selects all ul elements then finds the first visible li within each of them and applies the style.

    Here it is working: http://jsfiddle.net/FAY9q/5/

提交回复
热议问题