Ways to conceal and reveal content within div elements

I have a code snippet that is currently operational, but I am looking to enhance it by displaying one div at a time.

If you would like to view the code, please visit my CodePen link below:

https://codepen.io/danongu/pen/YzXvpoJ

Due to the extensive amount of HTML and CSS in the code, I refrained from sharing the entire content. My primary issue lies with the JavaScript portion.

My objective is as follows:

Upon clicking the 'Section A Book List' button, only the 'PREVIOUS VERSIONS A' and 'NEW VERSIONS A' sections should be visible.

Similarly, when selecting the 'Section B Book List' button, only the 'PREVIOUS VERSIONS B' and 'NEW VERSIONS B' sections should appear.

Regarding the black areas for 'Book 1' and 'Book 2,' I aim to display 'BOOK 1' when 'Book 1' is clicked, and 'BOOK 2' when 'Book 2' is selected.

Essentially, I require some form of conditional show/hide functionality. I attempted to implement this using jQuery in the provided CodePen example, but I encountered difficulties progressing beyond that point.

Your insights are greatly appreciated. While I made an initial effort, I reached an impasse during the process.

Answer â„–1

To make each section of the book list wrapper unique, you can assign a specific class or id to them. Here's an example:

<div id="bbl-wrapper1">
  <button class="toggle1">Section A Book List </button>
  <button class="toggle2">Section B Book List </button>

  <div class="clearfix" id="section-a">...</div>

  <div class="clearfix" id="section-b">...</div>
</div>

By default, you can hide #section-b:

#section-b {
  display: none;
}

You can use jQuery to control the visibility of each section like this:

$(document).ready(function() {
  var $secA = $("#section-a");
  var $secB = $("#section-b");

  $('.toggle1').click(function() {
    $secA.show();
    $secB.hide();
  });

  $('.toggle2').click(function() {
    $secA.hide();
    $secB.show();
  });
});

The same approach can be applied to manage BOOK 1 and BOOK 2 sections as well.

Note: Avoid using duplicate ids like bbl in your HTML as they must be unique for each element.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Could you provide me with a demonstration of cross-domain functionality?

Similar Inquiry: Methods to bypass the same-origin policy Let's consider two domains for this example - "" and "". The first domain "" is generating data in JSON format as shown below: { "str_info": [ { "str_name": "Mark ...

Embedding Facebook data into an HTML document

While I am able to retrieve data from Facebook and display it on the console, I am facing issues when trying to display it on an HTML page. I attempted using: $("#mydiv").text(data); or $("#mydiv").append(data); However, this displays [object Object] ...

AngularJS: Modifying values in one div updates data in all other divs

The webpage appears as shown below: https://i.sstatic.net/IxcnK.png HTML <li class="list-group-item" ng-repeat="eachData in lstRepositoryData"> <div class="ember-view"> <div class="github-connection overflow-hidden shadow-oute ...

Using AJAX to call a PHP function and transferring the resulting value to a specific div element

After implementing a function to include social buttons on my blog posts, I encountered an issue when loading more posts using ajax. I am struggling to find a way to call add_social_buttons() and pass the data to a specific div. As someone who is not well ...

Showing a PDF from a shared folder on a network using AJAX in HTML5

I'm facing a challenge with displaying a PDF on the web. The layout includes a dropdown menu on the left with various PDF file names, and upon selection, the chosen PDF should be displayed on the right using an ajax call. Since my PDFs are stored in a ...

Issues with jwplayer functionality

After downloading the necessary files and carefully following all instructions, I am still experiencing issues with the player not functioning as expected. <code> <html> <head> <script type="text/javascript" src="/jwpl ...

Tips for moving an input bar aside to make room for another

Is it feasible to have two input bars next to each other and keep one open until the other is clicked, then the first one closes as well? I attempted using a transition with "autofocus," but the bar ends up closing when clicked on in my site. If anyone ca ...

Creating an HTML table from dynamic JSON data - A comprehensive guide

I am in need of a solution to transform JSON data into an HTML table format quickly and easily. Can anyone provide guidance on effectively utilizing PartialView to recursively render tables, ensuring that most details are visible? ...

Utilizing jQuery and CSS to make an entire div clickable, and activate an 'a' tag hover state upon hovering

Looking to create a clickable link for the .wrapper div that directs users to the location of a.icon. Want the .wrapper div to activate the a.icon:hover state when hovered over, not just when hovering over the icon itself. Any assistance would be highly a ...

Why is applying CSS on an li element using .css() in JQuery not functioning?

Hey there! Could you please review my code? I'm attempting to add a top position to the <li> element using a variable in jQuery, but I'm not sure how to do it. Here's the code: <script> $(document).ready(function(){ ...

Change the order of numbering in ordered lists

I am seeking a way to change the ordering of an ordered list to be in descending order. You can view a live example here. Instead of having the counter span multiple ol elements, I would like the counter to reset after each ol. For the live demo, the des ...

Getting 100% height on floated neighboring divs: Tips and tricks

​<div id='container'> <div class='left'></div> <div class='right'></div> <div class='clear'></div> </div>​​​​​​​​​​​​​​​​â ...

Using jQuery to alter the background position of multiple backgrounds in CSS

I'm using jQuery to dynamically adjust the background image position of an element based on screen resolution. Here's the code: var pwwidth = $(window).width(); var pwheight = $(window).height(); var bg1posx = pwwidth - $('h1.portofolio&ap ...

Tips for styling the four DIV elements on a website's homepage with CSS

In my current project, I am working on a webpage that requires specific layout elements. On the web homepage, I need to split it into four sections positioned between the header and footer. The main code snippet for the homepage structure is as follows: ...

Find the string "s" within a div element aligned vertically, using Popper

Currently utilizing Popper from Material-UI <Popper id={"simplePopper"} open={true} style={{backgroundColor: 'red',opacity:'0.5',width:'100%',height:'100%'}}> <div style={{height:"100%", ...

Error in Chrome: Uncaught TypeError with JQuery Ajax - Unable to access property 'data' when null

Trying to retrieve results from the YouTube API, my code is as shown below: function Vget(strt){ $.get("https://gdata.youtube.com/feeds/api/videos", { q: "soccer, 'start-index':strt, 'max-results':"5", v:"2",alt:"jsonc" }, functi ...

Encountering Internal Server Error when C# WebMethod communicates with JavaScript AJAX call

I've encountered an issue where my AJAX call to a C# WebMethod is not returning the expected result. Instead, it keeps showing an "Internal Server Error" message. A button triggers a JavaScript function: <button id="btn" onclick="Create();">fo ...

Error Encountered: Anticipated 'styles' to consist of a series of string elements

I have attempted various solutions for this particular error message without any success. When launching my angular project using the angular cli via ng serve, everything runs smoothly with no errors. However, upon compiling it with webpack, I encounter th ...

Utilizing the setTimeout method in jQuery for multiple calls

Below is the function that I am working with: <script> var loop_handle; var xSeconds = 10000; // setting time interval to 10 seconds loop_handle = setInterval(function() { $('#overlay').fadeOut('fast'); $('#box').hide( ...

Convert a fixed Jquery div to absolute positioning when it reaches the end of the page

I've implemented a Jquery code that adds a fixed class to a div when scrolling down. However, I now want to remove this fixed class when it reaches the bottom of the page and replace it with a new one that includes position:absolute; and margin-bottom ...