Answer the question
In order to leave comments, you need to log in
Why doesn't js DOM work in react?
Good day, tell me why it is impossible to pick up all classes from the list elements through js DOM? And how to highlight clicked element in react? Only through ref ?
class MyComponent extends Component {
click=(e)=>{
document.getElementsByTagName('li').classList.remove("active")
e.target.className = "active"
}
render() {
return (
<ul>
<li onClick={(e)=>this.click(e)}>item1</li>
<li onClick={(e)=>this.click(e)}>item2</li>
<li onClick={(e)=>this.click(e)}>item3</li>
</ul>
)
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question