Difference between <div>and <div class | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Difference between <div>and <div class

I haven't understood how to differentiate between two elements. Please help

19th May 2018, 9:39 AM
Daudi Henjewele
Daudi Henjewele - avatar
3 Answers
+ 2
A <div> element basically helps you group elements so that you can access all of them together from elsewhere like a JavaScript or CSS file. But you can't identify which particular <div> you want to refer to unless you use a class or an id attribute. For example: HTML: <div class='redText'> <p>Sample</p> <p>Text</p> </div> CSS: .redText { color: red; } Here, we have nested the two <p> elements in the <div> element and given it a class name. This class name is used in the CSS to address all elements within it. Hope this heled :)
19th May 2018, 9:59 AM
Just A Rather Ridiculously Long Username
+ 1
<div> is an element class is an attribute. The difference is that you did not assign the class attribute to the first. You would assign a class attribute to a div in order to style it or use Javascript to grab it.
19th May 2018, 9:56 AM
Ulisses Cruz
Ulisses Cruz - avatar
+ 1
Thanks so much
19th May 2018, 10:11 AM
Daudi Henjewele
Daudi Henjewele - avatar