Finding and selecting sibling elements

You may not always know the specific element that you need to select. You may only know its parent, and therefore, you will need to search through the elements within the parent in order to find the specific element that you are looking for. This recipe will show you how to find elements through their parents in various ways.

Getting ready

Open your text editor or IDE with the latest version of jQuery, ready to be included into the HTML page that you will create as part of this recipe.

How to do it…

To learn the various ways in which jQuery can help you to search for DOM elements based on a parent element, perform each of the following steps:

  1. Create a web page with the following HTML and JavaScript code:
    <!DOCTYPE ...

Get jQuery 2.0 Development Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.