Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

248
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda