I ran into a reaction I couldn\'t explain today while working with some very basic Jquery today and I was hoping one of you could explain to me what is occurring to lead to
Spaces indicate matching against descendants. For every space, you're descending (at least) one level and applying your selector to the children of the previously selected elements.
For example:
div.container.post
Will match a ...will match any element with the class This will match You can think of it as matching in stages: First elements matching In your case, Spaces work exactly the same way as chaining multiple calls to container and post classes, while the following:
div.container .post
post which descend from a container.
, but it will also match any .post, no matter how deeply nested it is:
div.container are found, and then each of those elements (and all of their sub elements) are searched matches against .post.div.Object :last first finds all Object class, and then searches within each of those for elements matching :last, that is any element which is the last element in its container. This applies to both and .
find, so if you understand how that works, you can understand how spaces affect a selector. These are identical:$('div#post ul.tags li');
$('div#post').find('ul.tags').find('li');