tags:

views:

88

answers:

3
1.parent > son
2.parent>son

the only difference is whether there is space before and after ">",

and how is this kind of selector supported by browsers?

+1  A: 

Absolutely, spacing doesn't matter. Of all the relevant browsers on the market, only IE6 does not support this. All the rest do.

IE6 does not support anything but plain descendant selectors, like "parent son".

Aleksandar Vacic
Spacing does matter, just not in the case of `>`. Eg `p.foo` targets different elements than `p .foo`
Crescent Fresh
I agree, but he's specifically asking about child selectors, where it's irrelevant.
Aleksandar Vacic
+3  A: 

Yes, that is called a child selector, and the spaces are irrelevant.

Most browsers support it, with the exception of IE6 and lower. Here's a handy compatibility table.

Paul Dixon
A: 

Writing selectors together without spaces are used when you refer to the same element. The div.content selector matches an element that is a div, and also has the class content.

As the > operator describes a direct parent-child relation, the expression to the left can not match the same element as the expression on the right. An element can not be it's own child. Therefore writing it without spaces instead has the same meaning as writing it with spaces.

Guffa