I
I
IIITRIX2018-10-25 20:42:05
React
IIITRIX, 2018-10-25 20:42:05

How to add class to div on click?

It is necessary that when you click on the input, another css class is assigned to the div,
if you click to another place on the screen, css should be reset, I
try this, but something doesn’t work!

return classNames({
      'exp':  this.state.clicked,
      'noexp':  !this.state.clicked
    });
{this.getClassNames()} onClick={this.setState({clicked: !this.state.clicked})

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-10-25
@IIITRIX

Why onClick? - when you click on the input again, the class will be deleted, and you will not process a click outside the input in this way. Probably should use onFocus and onBlur. For example .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question