So far you've learned how to identify elements using attributes and how to identify elements using their location. Now, let's combine both!
Let's look at a previous HTML example to identify an element using attribute and location.
Let's say, for example, that we want to use td.label as our jQuery selector. Easy enough, right?
However, if you take a closer look at the example above, you see that there are two td.label elements in the HTML. So how can we uniquely identify one td.label element over the other?
To uniquely identify an element, we will need to combine both the element's attributes and location.
Let's try to identify the highlighted element below.
In this scenario, we also need to take into consideration the parent element of td.label so we can differentiate it from the first one. To do this, we will use a [space].
Using a [space] tells our selector to look for the child or descendant of an element. This means we will look for "children" of the first element that match the second element. This is used to find an element based on one of its "parents".
For the example above, to uniquely identify the second td.label, we will write the following jQuery selector:
div#contentWrapper td.label
This means that we are looking at the child element of div#contentWrapper that matches td.label. To put it alternatively, we are looking at the td.label element whose parent is div#contentWrapper.