Changing Elements in JavaScript
Changing Style
The style of HTML elements can also be changed using JavaScript.
Further Explanation:-
All style attributes can be accessed using the style object of the element. When we access the style object, then we can change every CSS property of that particular object. All CSS properties can be set and modified using JavaScript. However, instead of dashes(-) we use camelcase-like font-size will turn into fontSize.
Syntax:-
document.body.fontSize = "2rem";
Changing Attributes
Once you have selected the element(s) you want to work with, you can change their attributes. We can change the text content of an element using the innerHTML property. In the same way, we can change the attributes of elements. Practically all attributes of an element can be changed using JavaScript.
Syntax:-
document.querySelectorAll("input[type='radio']").checked = true;