JQuery: Novice to Ninja- P4:No matter what kind of ninja you are—a cooking ninja, a corporate lawyer ninja, or an actual ninja ninja—virtuosity lies in first mastering the basic tools of the trade. Once conquered, it’s then up to the full-fledged ninja to apply that knowledge in creative and inventive ways. | 22 jQuery Novice to Ninja will happily select as many elements as we point it to. If there were multiple tables or any other elements for that matter that also had the class data they d all be selected. For that reason we ll stick to using the id for this one Just like with CSS we can select either .data or the more specific . By specifying an element type in addition to the class the selector will only return table elements with the class data rather than all elements with the class data. Also like CSS you can add parent container selectors to narrow your selection even further. Narrowing Down Our Selection We ve selected the table successfully though the table itself is of no interest to us we want every other row inside it. We ve selected the containing element and from that containing element we want to pick out all the descendants that are table rows that is we want to specify all table rows inside the containing table. To do this we put a space between the ancestor and the descendant celebs tr You can use this construct to drill down to the elements that you re looking for but for clarity s sake try to keep your selectors as succinct as possible. Let s take this idea a step further. Say we wanted to select all span elements inside of p elements which are themselves inside div elements but only if those divs happen to have a class of fancy. We would use the selector p span If you can follow this you re ready to select just about anything Testing Our Selection Right back to our task at hand. It feels like we re getting closer but so far we ve just been selecting blindly with no way of knowing if we re on the right path. We need a way of confirming that we re selecting the correct elements. A simple way to achieve this is to take advantage of the length property. length returns the number Selecting Decorating and Enhancing 23 of elements currently matched by the selector. We can combine this with the good ol trusty alert statement to ensure