Aryan PrajapatKnowledge Contributor
How should we change the style/class of an element?
How should we change the style/class of an element?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Questions | Answers | Discussions | Knowledge sharing | Communities & more.
First of all, we can use the className to assign a value directly to the class. If any such classes are already present on the element, then this will override them.
For getting the value of class on the element, we can add multiple spaces using className.
Given the following way, we can change the class of an element:
document.getElementById(“myText”).style.fontSize = “20”;
or,
document.getElementById (“myText”).className = “any class”;