When the user clicks, display one div and conceal the others

https://codepen.io/leiacarts/pen/PoqRxNZ

I need assistance with two specific tasks related to my website layout. Firstly, I am struggling to ensure that images displayed in the red sections remain constrained and automatically resize within the content div without breaking the overall layout. Secondly, I would also like to implement a feature where clicking on a section hides the images contained within it. Any help provided towards achieving these goals is greatly appreciated.

Here is the HTML code snippet:

<div class="section">
  <div class="bookmark">&#8593; ten &#8596; sion &#8595;</div>
  <div class="content"><p></p>
    <!-- <div class="space"></div> -->
      <!-- <img class="fit" src="images/ziptiesmall.png">
      <img class="fit" src="images/ziptiesmall2.png">
      <img class="fit" src="images/ziptiesmall3.png"> -->
  </div>
</div>

This is the JavaScript snippet:

var sections = document.querySelectorAll(".section")

sections.forEach(function(section) {
  section.addEventListener("click", expandSection);
})

function expandSection(event) {

let section = (event.target.classList.contains("section")) ? event.target : event.target.parentNode;


sections.forEach(function(section) {
  section.classList.remove("open")
})

section.classList.add("open");
}

Answer №1

I recently assigned this class to the remaining divs that were missing images, resulting in them displaying the red content div. By removing the 100% width and image text from each column, as well as creating IDs for each column and adding background images, you'll be all set :).

.content.bg.zip {
    margin-left: 40px;
    /* width: 100%; */
    background-color: #000;
    background-image: url(images/ziptiepattern.png);
    background-repeat: repeat;
}

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

What is the most efficient way to create multiple nested property objects in a shorter amount of time?

Currently, I am utilizing mongoDB for a data migration project where queries are written in plain JavaScript/JSON format: queryObj = {}; // main object passed to mongodb for queries The code snippet below is causing an error: queryObj[inObj.row]['$ ...

Displaying a Google map within a jquery modal window upon hovering over a designated location

I'm looking for a way to display a Google map in a jQuery modal window when I hover or click on a cell in a table that contains a location. I'm new to JavaScript and the Google Maps API, so any assistance would be greatly appreciated. Thanks! ...

Obtain the value of a table cell dynamically using jQuery

I'm facing an issue with a table cell that is being dynamically changed to a textarea. When the user clicks on the cell, they should be able to input some text: $("#myDataTable tbody tr td:nth-child(4)").click(function(e) { if ($(this).p ...

Transmit information from the main directive to the subordinate directive

Hi everyone, I have a quick question.. I'm working on a directive that includes an ng-repeat and transclude, with several child directives inside it that need to inherit specific objects from each iteration... So far, I've only managed to achiev ...

Encountering a snag while setting up Google authentication on my website

Currently, I am in the process of integrating Google Authentication into my website. However, I have run into an error related to session management that reads as follows: TypeError: req.session.regenerate is not a function at SessionManager.logIn (C:&bso ...

Is it feasible to utilize jQuery mobile without the use of AJAX, relying only on styles?

While I am aware of the jQuery Mobile download-customizer, I am struggling to determine which options need to be selected. It appears that the styles for input elements are somehow connected to the AJAX functionality? All I really desire is to have stylis ...

Using jQuery to replace text with regular expressions and a custom find function

I am struggling to figure out how to use regex to replace a specific part of a URL within a certain div. I want to change /images/ to a new folder called /design/abtester/nyaproduktbilder/ because I am running a sitewide A/B test with new product images. ...

What methods are available to adjust the header color on various pages?

I have a solution that works for one location, but I need to add red color to multiple locations. How can I achieve this? import { useRouter } from "next/router"; function Header() { const router = useRouter(); return ( <> & ...

Tips for saving information from a textarea into an HTML file

I have a unique question regarding the usage of $fopen and $fwrite functions. My goal is to include a button named "save as HTML" below a textarea. Upon clicking this button, I want a popup box to appear mimicking the 'save as...' dialog window ...

The AJAX request successfully retrieves data, but the page where it is displayed remains empty

I have come across similar questions to mine, but I have not been successful in implementing their solutions. The issue I am facing involves an AJAX call that is functioning correctly in terms of receiving a response. However, instead of processing the re ...

Create a webpage in full screen mode with a video player that fills the entire screen

Here is the HTML code I am working with: <div id="container"> <video id="video" src="video.ogv" loop></video> </div> The "container" div and video element occupy the entire screen. #container { po ...

When working with Node.js and Express, encountering the error message "data.push is not a

I am encountering an issue when trying to add a new task to the list of all tasks. The error message I receive is TypeError: allTasks.push is not a function data contains JSON data that has been retrieved from a file using the fs method var allTasks = JS ...

"Exploring the vibrant world of colors with Colorbox: a

In one of my projects, I am utilizing colorbox to create a video gallery. One feature I am trying to implement is to display the video description underneath each video when opened in the colorbox modal. Currently, here is what I have: <script> $( ...

The resizing of images is limited to when the browser is refreshed for responsive

Hey there, I'm currently facing an issue with a responsive image gallery using jQuery cycle. If you want to check out my fiddle, here's the link - https://jsfiddle.net/qxyodctm/5/ <html>See jsfiddle</html> The problem occurs when t ...

What is the process of invoking the POST method in express js?

I've been diving into REST API and recently set up a POST method, but I can't seem to get it to work properly. The GET method is running smoothly in Postman, but the POST method is failing. Can someone lend a hand in figuring out where I'm g ...

calendar input type for both internet explorer and firefox

I frequently utilize the input type calendar on my website's intranet, but unfortunately, it only seems to work properly in Google Chrome and not in other browsers. As a solution, I have developed a code for a CSS/JavaScript calendar that I would like ...

Using Vue's transition mode alongside v-for and v-if does not appear to function correctly

When using Vue with Vuetify, I am trying to dynamically change v-cards with the help of animate.css. However, I have run into an issue. The out-in mode is not working in this scenario as both fade-in and fade-out animations occur simultaneously. Is there a ...

Is there a way to retrieve the href value from a modal window upon clicking the link?

When clicking on the a href, I am attempting to retrieve a value in my pop-up window. I am using magnificPopup JavaScript Below is the code for my a href tag and I want to fetch the "data-stream" value in the pop-up window. <a class="popup-with-zoom ...

Using Sequelize and Express API for verification in the controller is an essential component of building

I'm currently working on building the API for my web app, utilizing Sequelize and Express. I have set up models with Sequelize and am in the process of developing controllers and endpoints. My main query is: Should I perform data validation checks be ...

Embed watermark on the Username and Password fields of asp:Login control

Seeking help to watermark the Username and Password fields of asp:Login controls using jQuery, I have attempted different methods to reference the control ID: $('#<%=ClientID.Login1_UserName %>').watermark('watermark', 'User ...