jquery, find next element by class
To find the next element with the same class:
$(".class").eq( $(".class").index( $(element) ) + 1 )
You cannot use next() in this scenario, if you look at the documentation it says:
Next() Get the immediately following sibling of each element in the set of matched elements. If a selector is provided, it retrieves the next sibling that matches the selector.
so if the second DIV was in the same TD then you could code:
// Won't work in your case
$(obj).next().filter('.class');
But since it's not, I don't see a point to use next(). You can instead code:
$(obj).parents('table').find('.class')
In this case you need to go up to the <tr>
then use .next()
, like this:
$(obj).closest('tr').next().find('.class');
Or if there may be rows in-between without the .class
inside, you can use .nextAll()
, like this:
$(obj).closest('tr').nextAll(':has(.class):first').find('.class');