[Solved] Which is fastest? closest() vs manual traversing in jQuery [closed]


These do different things.

.closest('.DivB') will traverse the DOM tree up until it finds an element that matches the selector (probably none).

.parent().next() will do what it looks like it will do, find the parent then its next sibling.

What you want is .closest('td').find('.DivB') and don’t worry about micro-optimizations. It won’t break when the DOM changes slightly and will work in the scope of a single table cell which is probably what you need.

Edit: the question has been heavily edited, but .closest() still doesn’t do what you think it does. Now you want $('.LinkB').siblings(".LinkG");

solved Which is fastest? closest() vs manual traversing in jQuery [closed]