Element indicates the html elements which consists of html tags and contents present inside it.
How to select and change the element?
Some important selectors are explained below,
- id selector
- class selector
We can select the html element by id value using getElementById method.
Example 1 - set background css property
In the above example, we are finding the element which has id value as testid and it is stored in elem variable.
Next by using style property of the elem variable we are changing the background color of the specified element.
elem.style - using this we can change all the css properties, in this example it is used to set the background css property as red.
Example 2 - get background css property value
In a html document, various html elements may contain same class value, so this must be returned in an array.