JavaScript JavaScript and the DOM Making Changes to the DOM Getting and Setting Text with textContent and innerHTML

why p.description ? wouldnt just .description work?

3:50 video mark. code line number 2.

3 Answers

Niclas Hilmersson
Niclas Hilmersson
8,294 Points

well p.description means target all <p> tags with a classname of "description" in the document.

So if there is a <h1> which also has a class of description. It wont be targeted right? Because p.desciption will explicitly target description in p tag across the document.

Thanks again for explaining it to me i was lost for a while

Niclas Hilmersson
Niclas Hilmersson
8,294 Points

Yes it would. But why he is using that is because of specificity. He just wants to be very specific on what he targets to not cause problems in the future if you add different elements with the same class.

So p.classname means all the classes which are in the <p> tag?

All the classes as in whatever the class name is specified