0

I understand that a space between CSS selectors indicates nesting. For example, .funny p would select all paragraph elements within an element of the class "funny", and I would similarly (from this logic) expect div .funny to select all "funny" elements within a div tag. However, I never actually see nested selectors in that form in any documented examples, but see quite a bit of those in the form div.funny. Is this simply nice shorthand for what div. funny would convey, or is there in fact a subtle difference I'm missing here? Thanks!

2 Answers 2

5

div.funny Selects all divs that have the class funny

While

div .funny Selects all elements with the class funny that are descendants of a div.

The space makes a significant difference

Sign up to request clarification or add additional context in comments.

1 Comment

To the anonymous downvoter, care to leave a comment as to what's wrong with this answer?
-1

div.funny in CSS would target a div with the class name of funny, which is also what you'd get if you were to use that as a jQuery selector.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.