p #test VS #test p | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 3

p #test VS #test p

For the last question, the ā€˜correct answerā€™ is: #test p But wouldnā€™t: p #test be just as right? The first says ā€œall classes named ā€˜testā€™ of <p>ā€ The second says ā€œall <p>s with the class of ā€˜testā€™ā€ I just find the second more readable, and both ways work, yet I got it wrong when I entered it the second way.

7th Feb 2019, 2:48 PM
Chester
1 Resposta
+ 4
Hi Chester ! An "#" stands for ID attribute, class is a period "." and therefore both work, because ID should be unique and has priority over element AFAIK (may anybody please correct me if I am wrong) p #test would select all P with ID test. Since ID should be unique, it only selects the element with ID test. #test p would select the only one P element with ID test, if your P element has an ID attribute. As for classes: p .test would select all children of P with class test. .test p would select all P elements which are children of elements with class test. But only p.test would select all P with class test. Take a look at my code: https://code.sololearn.com/WIx3N4EbAU6P/?ref=app
14th Mar 2019, 5:44 PM
Pete Wright
Pete Wright - avatar