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

169
Views
Add and remove function onclick with js

So I want to add a function that when I click a div it moves, but when I click something else it moves back to its original position, I want to use gsap here too. I tried using an if else statement but I didn't know want to put in here(The part where there is two stars):

let btnSide1 = document.querySelector('.button-side-one'),
        btnSide2 = document.querySelector('.button-side-two'),
        btnTop = document.querySelector('.button-top'),
        btnBig = document.querySelector('.button-big');
if (btnSide1 = **active**) {
  gsap.to(btnSide1, .5, { x: 3 })
} else {
  gsap.to(btnSide1, .5, { x: 0 }) 
}

here is the codepen link for this: https://codepen.io/sowg/pen/GRvQxpN

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I figured this out I used toggle class list for this,

Here is how it works:

// Variables

btnSide1.onclick = function () {
    btnSide1.classList.toggle("activex1");
};
.activex1 { left: 30vmin !important }

So when I click on the div it moves position

about 4 years ago · Juan Pablo Isaza Report

0

You have a typo.

if (btnSide1 === active)
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!