The CLASS attribute is used to indicate the class or classes that a tag my belong. It is associate an HTML element tag with a name. The CLASS name doesn't have to be unique in a document. In simple terms class word means a section and it's can be used every HTML elements. The CLASS name is case sensitive, which means it define Lion and lion have two different class name. At the present time all popular browsers supported class attribute.
Syntax :
<tag class="name">content</tag>
Note: In this example, I have given a class name "point" in <paragraph> html element.
Use Multiple Class Name :
It also is possible to write or give multiple values for the class attribute separated by white space in the document.
Syntax :
<tag class="name1 name2 name3">content</tag>
Note: We could define three classes for the one <bold> html element.
Important :
Class Attribute Use In CSS As Selector :
In CSS, if you write or to create already a class name, write a period (.) character, followed by a class name. Then define the CSS properties and its value within curly braces {}.
Class Attribute Use In JavaScript :
The CLASS name can also be used by JavaScript to perform certain tasks for a specific element. JavaScript can access html elements with a specific class name with the getElementsByClassName() method. The script tag developer can use on both sections body or add it to the head section.
Use One Class Name In Multiple Html Element :
Different or multiple html element can point to the same class name. It is used for at a time access all elements for styling or performing a given task in javascript.
0 Comments