0

I do following statement to add 'hold-transition login-page' class to the <body id='the_body'> element

import React, { Component,useEffect } from 'react';
export default class Login extends React.Component {
componentDidMount() {
document.getElementById("the_body").classList.add('hold-transition login-page')
}
render() {
return(
<div className="login-box">
...some html script
</div>
)
}

but I get this error

InvalidCharacterError: String contains an invalid character
componentDidMount

I am already make simple javcript code inside  `componentDidMount()`

componentDidMount(){
 alert('test javascript inside jsx');
}

it is running well. but why my dom statement is error?. finaly I hope you to fix my problem, thank you

1

1 Answer 1

1

This is not how people modify classes with React but the problem in your example is that "hold-transition login-page" is not a valid class name.

If you want to add multiple class names you should try

classList.add("hold-transition", "login-page")
Sign up to request clarification or add additional context in comments.

1 Comment

thank you bro, I realize my mistake now I clone my dom statement 1.add class hold-transition 2.add class login-page classList.add("hold-transition") classList.add("login-page") its' work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.