Originally Posted by rnd me
That doesn't select the second div, it selects the first.
If you want the second div, you can use
, and to change the text of the paragraph where class="selected" use
$("div:eq(1) p.selected").text("new text here")
The reason why your code wasn't working is because .next() is like a for loop on a group of selected elements, but your group of selected elements had only one element in it-- the first div.
(EDIT) No, I was mistaken, that's not why. I was misreading the manual. The reason why is because you giving the .next() function a selector of ".selected", which is an additional filter applied to the next element. So in your case, the second div would only be selected if it has a class="selected". It doesn't check the div's children for this selector.