This is a function I am using in my application so I could use keyboard keys to browse through a lit of tasks. My problem was that som of the tasks were hidden (in my example did not have the class “visible”) so I did not want to go through them when using the up and down keys while browsing the list of tasks. I only wanted to use click() on the next visible list item.
I had to use prevAll() & nextAll with a specific slection of a class ‘visible’ but and reaching for the first match.
This the particular piece of code in caffeescript (again, its just jquery without brackets)
prev_list = $(current_list).prevAll('li.visible:first')
My function is a bit longer as I am checking by other stuff but this is the simplified version of it.
focus_on_prev_task = ->
$('#data_ajax_cover li').each ->
current_list = $(this)
prev_list = $(current_list).prevAll('li.visible:first')
$(prev_list).click()