Context matters (Should know)

So far I've mentioned vaguely something called context that can be used during a selection. This recipe illustrates how and why we use the second parameter of jQuery, context.

How to do it...

Our goal is to apply a border to all of the <li> descendants of an element having ID content, using the context parameter. Perform the following steps:

  1. Create a copy of the child-filters.html file and rename it as context-matters.html.
  2. Edit the <head> section of the page adding this code:
        $(document).ready(function() {
            $('li', '#content').css('border', '2px solid #000000');
  3. Save the file and open it with your favorite browser.

How it works...

This recipe is very simple because I want you to focus on the consequences ...

Get Instant JQuery Selectors now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.