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

249
Views
How can I use JavaScript to delete a class?

I am at an academy where they are asking me to put in a 800px image and then use the <img>: class = "small" tag to make it shrink and then they tell me this:

The goal of this part of the project is that you will use JavaScript to either remove this "small" class (and thus the image will grow) or reposition it (thus it will become small again) when the user clicks.

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

0

You need to use the classList property of the HTML element.

// Select the element
const myElement = document.querySelector("#my-element");

// Add a class
myElement.classList.add("class-to-add");

// Remove a class
myElement.classList.remove("class-to-remove");

Here is the corresponding documentation: https://developer.mozilla.org/docs/Web/API/Element/classList

about 4 years ago · Juan Pablo Isaza Report

0

// garp the image by it's className
const myImage = document.querySelector('.myImage')

// add event listener to respond click event
myImage.addEventListener('click', () => {
  // it will toggle on and off whene ever used clicks it 
  myImage.classList.toggle('small')
})
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!