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");
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.