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

117
Visualizações
How to alter elements with conditionals? Example provided

I recently started an online class and it has not been easy for a new beginner, despite what the course said. Anyways, on the assignment, we are pretending to be web designers for a client. Currently, on one of the pages, they have a "more" feature so you can continue reading the paragraph. They now want us to collapse the text and create a "less" feature. They added that we should be using the Java Script and code that they provided. I will attach them below. I guess my question is, I'm not sure how to format this code and how to use each of them to create this "less" feature on the paragraphs. As I said, I'm a total beginner and I definitely don't think this class was created for people like me so apologies if this does not make sense or has correct terminology.

Java Script: if ( condition ) { action } else { alternative_action }

Code: $("#q1 .less").removeClass("hidden"); $("#q1 .more").addClass("hidden");

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Assuming you've got 2 divs, 1 with class 'more' and the other with 'less' and you need to swap between them, I'd suggest something like this:

if($('#q1 .less').hasClass('hidden')){ // check if the 'less' item is already hidden
  $('#q1 .less').removeClass('hidden'); // show less and hide more
  $('#q1 .more').addClass('hidden');
}else {
  $('#q1 .more').removeClass('hidden'); // show more and hide less
  $('#q1 .less').addClass('hidden');
}

See https://api.jquery.com/hasclass/, https://api.jquery.com/addclass/ and https://api.jquery.com/removeclass/ for information about the jQuery functions used.

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