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

127
Views
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 answers
Answer question

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 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!