How can I traverse DOM elements using jQuery

jQuery, DOM traversal, parent, children, siblings, next, prev
This page demonstrates how to traverse DOM elements using jQuery methods such as parent(), children(), siblings(), next(), and prev().
<script> $(document).ready(function() { // Select the first list item and traverse its parent var firstItem = $('li:first'); var parent = firstItem.parent(); // Get parent var siblings = firstItem.siblings(); // Get siblings var nextItem = firstItem.next(); // Get next sibling var prevItem = firstItem.prev(); // Get previous sibling // Example usage console.log('Parent:', parent); console.log('Siblings:', siblings); console.log('Next Item:', nextItem); console.log('Previous Item:', prevItem); }); </script>

jQuery DOM traversal parent children siblings next prev