Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

118
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda