1

I have a <div> with many <ul> descendants with different classes, and I am calling a function on this <div> which modifies the last <ul> with a given class. How do I select the last <ul> descendant with a specified class using $(this) jQuery selector?

Seth
  • 528
  • 3
  • 16
  • 32
Dronacharya
  • 471
  • 1
  • 4
  • 15

2 Answers2

5

You can use the last method:

var last = $(this).find("ul.someClass").last();

Or the :last selector:

var last = $(this).find("ul.someClass:last");
James Allardice
  • 164,175
  • 21
  • 332
  • 312
0

i think it should work also.

var uls = $(this).find("ul.someClass")

var lastUl = uls[uls.length - 1];
erimerturk
  • 4,230
  • 25
  • 25