This might be tricky.
Php will generate:
<li>element</li>
<li>element</li>
<li class="alt">element</li>
<li class="alt">element</li>
<li class="alt">element</li>
<li>element</li>
<li>element</li>
<li class="alt">element</li>
<li class="alt">element</li>
<li class="alt">element</li>
<li>element</li>
What I need is a way to find the li elements with the .alt class until the li elements start. So...
<li>element</li>
<li>element</li> // if I click on this one, it will select
<li class="alt">element</li> // this one
<li class="alt">element</li> // and this one
<li class="alt">element</li> // and this one
<li>element</li> // stops selecting here
<li>element</li>
<li class="alt">element</li> // doe not this one
<li class="alt">element</li> // or this one
<li class="alt">element</li> // or any other .alt
<li>element</li>
I tried doing this with .find(), but I can't find a way to divide the .alt elements into groups and isolate the first one.
Any braniacs there with a good idea?
If you're using jquery 1.4 you can use the new nextUntil method.
http://api.jquery.com/nextUntil/
edit - example:
$("li").click(function() {
$(this).nextUntil("li[class='']").each(function() {
console.log($(this));
});
});
try (couple of edits but think I have it)
$('li:contains(element)').click().find('li:contains(element):not[alt]:first').prevAll('li.alt');
couldn't you add an extra class for the lis thats gonna be retrieved?