janjanjan
janjanjan

Reputation: 57

jQuery multiple filters on selector

I'd like to select last div which id starts with "level":

var div = $('div[id^="level"]:last');

But as well I'd like to select the last and visible one. How could I perform that? Following doesn't work:

$('div[id^="level"]:last:visible');

I tried couple different combinations but none worked.

Upvotes: 2

Views: 895

Answers (2)

j08691
j08691

Reputation: 207891

Try switching your :last and :visible that was you first filter all the elements by their visibility, and then filter for the last one.

$('div[id^="level"]:visible:last');

Upvotes: 2

intelis
intelis

Reputation: 8058

Maybe something like this?

var div = $('div[id^="level"]:last').filter(":visible");

Upvotes: 2

Related Questions