Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

226
Views
JQuery toggleClass not working in React.js when i try to click on the element

If i try to toggle the class(active) nothing hapens just flashing in the dev tools. Here is the picture.

And here is my code:

let usercontainer = document.querySelector(".user-container")
let user = document.querySelector(".user")
    
$(user).on('click', function() {
    $(usercontainer).toggleClass(".active")
})

Here is how i render:

<div className="user">
                <img className="upic" src="https://cdn.discordapp.com/avatars/477814830598717441/3d84322f38d500a46e017951569a8c42.webp?size=1024" alt="usericon" />
                <a className="uname">F4||1ng</a>
                <div className="user-container">
                    <div className="logout-container">
                        <div className="logout">Kijelentkezés</div>
                    </div>
                    <div className="notes-container">
                        <div className="notes">Jegyzeteim</div>
                    </div>
                </div>
            </div>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Few tips here:

  • Use the $ shortcut instead of document.querySelector
  • When using toggleClass, use the class name without the dot in front.

Something like this:

let usercontainer = $(".user-container")
$(".user").on('click', function() {
  usercontainer.toggleClass("active")
}) 

See https://codepen.io/jr-duboc/pen/NWXepRG

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!