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

1
  • 1
    To the anonymous downvoter, care to leave a comment as to what's wrong with this answer?
    – j08691
    Commented May 1, 2017 at 13:18
-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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.