views:

1490

answers:

3

i am abit confused between these 2 selectors

div p

selects all p within a div whether or not its an immediate decedent? so if the p is inside another div it will still be selected?

then child selectors

div > p

whats the difference? does a child mean immediate child?

eg.

<div><p>

vs

<div><div><p>

both will be selected?

+4  A: 

Yes, you are correct. div p will match the following example, but div > p will not.

<div><table><tr><td><p> <!...

The first one is called descendant selector and the second one is called child selector.

çağdaş
+6  A: 

Just think of what the words "child" and "descendant" mean in English:

  • My daughter is both my child and my descendant
  • My granddaughter is not my child, but she is my descendant.
RichieHindle
+3  A: 

Be aware that the child selector is not supported in Internet Explorer 6. (If you use the selector in a jQuery/Prototype/YUI etc selector rather than in a style sheet it still works though)

rlovtang
i am thinking i use that in css. but in jquery i detect if browser is ie6 (in jquery can i do this? or do i need to use <!--[if IE 6]>) and add a class
iceangel89
jquery do feature sniffing rather than browser sniffing so I don't think you can detect if browser is ie6. And you shouldn't. Best thing is to include an additional style sheet for ie6 with conditional comments like you described.
rlovtang