I have a load of LIs inside an UL, and each one has a unique ID.
Given two IDs, what's the best way to select the two corresponding LIs, and all the LIs in between?
Thanks!
I have a load of LIs inside an UL, and each one has a unique ID.
Given two IDs, what's the best way to select the two corresponding LIs, and all the LIs in between?
Thanks!
You can do it like this:
$('#id').nextUntil('#id2').andSelf().add('#id2')
It's important to note that .nextUntil()
does not include the element it's going until, it stops with the one before it. To add that element, you need to call .add(selector)
on the end.
You also need a .andSelf()
to include the first element
To select the All LIs in Between UL
$(document).ready(function(){
$("li[ID*=ids]").css("bacground-color","red");// contian common world ex ids1
});