How can I make the Box div bigger or smaller?

My goal is to expand and collapse the slider div only for the box where the user clicks. I have achieved this functionality, but a problem arises when I click "read more" - all the boxes expand, which is not the desired behavior. I want only the specific box to expand while the rest remain collapsed.

Below is the code snippet of what I am currently implementing:

<style>
  #readmore1 {display: none;}
  #readmore2 {display: none;}
  #readmore3 {display: none;}
</style>

<div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
  <div class="carousel-inner">
    <div class="carousel-item active">
      <div class="container">
        <div class="row">
          <div class="col-md-4 testSliderBox">
            <!-- Content here -->
          </div>
          <div class="col-md-4 testSliderBox">
            <!-- Content here -->
          </div>
          <div class="col-md-4 testSliderBox">
            <!-- Content here -->
          </div>
        </div>
      </div>
    </div>
    <div class="carousel-item">
      <img class="d-block w-100" src="..." alt="Slide 2">
    </div>
  </div>
  <!-- Controls -->
</div>

<script>
  // JavaScript functions for handling read more functionality
</script>

Currently, all boxes expand when clicking "readmore." My goal is for only the selected box to expand without affecting the others. I welcome any suggestions or feedback on what may be going wrong in my implementation.

Answer №1

After implementing your solution, I noticed a small error when interacting with the third box. Instead of readdots1 and readmore1, it should be readdots3 and so on.

function myFunction1() {
   var dots = document.getElementById("readdots1");
   var moreText = document.getElementById("readmore1");
   var btnText = document.getElementById("myBtn1");

  if (dots.style.display === "none") {
   dots.style.display = "inline";
   btnText.innerHTML = "Read more"; 
   moreText.style.display = "none";
    } else {
   dots.style.display = "none";
   btnText.innerHTML = "Read less"; 
   moreText.style.display = "inline";
   }
   }


 function myFunction2() {
 var dots = document.getElementById("readdots2");
 var moreText = document.getElementById("readmore2");
 var btnText = document.getElementById("myBtn2");

 if (dots.style.display === "none") {
   dots.style.display = "inline";
  btnText.innerHTML = "Read more"; 
  moreText.style.display = "none";
  } else {
   dots.style.display = "none";
   btnText.innerHTML = "Read less"; 
   moreText.style.display = "inline";
  }
  }


function myFunction3() {
 var dots = document.getElementById("readdots3");
 var moreText = document.getElementById("readmore3");
 var btnText = document.getElementById("myBtn3");

 if (dots.style.display === "none") {
  dots.style.display = "inline";
  btnText.innerHTML = "Read more"; 
  moreText.style.display = "none";
  } else {
  dots.style.display = "none";
  btnText.innerHTML = "Read less"; 
  moreText.style.display = "inline";
}
}
...

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

The search bar extends beyond the dropdown in a boostrap collapse scenario

Currently, I'm facing two issues that I need assistance with: On smaller screens, the search bar drops out of the navbar collapse inexplicably, and I'm struggling to identify the cause. The width of the search bar seems to be overriden by A ...

What is the reason for not modifying the filtered and sorted data?

I am currently working on implementing filter options for an item list, but I am facing an issue where the filtering does not work when selecting dropdown options. Array in App.jsx const cameraShowList=[ {id:1,model:"Canon",title:"Canon ...

Issue with incremental static generation in version 13 not functioning as expected

Is ISR working for anyone in the NextJS 13 Beta version? I have set revalidate to 15 as follows. export const revalidate = 15; However, even after running `npm run build`, the page still remains a statically generated site (SSG). The symbol is showing u ...

Place the <span> element at the bottom of the <ul> list

Struggling to align the captions of an image carousel at the bottom of the <ul>. No matter what I try, it just doesn't look right. Check out my Fiddle here Below is the HTML structure: <div class="carousel"> <ul> <l ...

Adjusting the height of an IFRAME on the fly

One solution to dynamically fix the height issue of Google Trend charts is by modifying the code output. An example of this can be seen in the code snippet below: <iframe width="600" height="320" src="http://www.google.com/trends/fetchComponent?hl=en-U ...

React and Material-UI issue: Unable to remove component as reference from (...)

My React components are built using Material-UI: Everything is running smoothly MainView.js import React, { Component } from 'react'; import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider'; import { List, ListItem } from ...

Infura makes ten calls to eth_getBlockByNumber for every eth_call request

Currently, I am in the process of creating a straightforward nextjs API route (https://nextjs.org/docs/api-routes/introduction) that is linked to the Ethereum blockchain for executing a view function (which doesn't require any gas) from a smart contra ...

Navigation for GitHub pages

I've been working on this for what feels like forever. The persistent Error 404 I'm encountering is with the /Quest/questlist.txt file. https://i.sstatic.net/NYYRa.png Here's the code snippet I've been using: ``// QuestCarousel.tsx ...

Identify all div elements with a specific class within the parent div

How can I use query selector to exclusively target the p and p2 divs inside of a r class, without selecting them if they are outside of that class? <div> <div class="r"><div class="p"></div><div class="p2"></div></di ...

Saving the state of checkboxes in Angular Material

I am trying to figure out a solution for storing checkbox values, specifically whether they have been checked before or not. For example, I have this dialog: https://i.sstatic.net/c16Ju.jpg After clicking on a checkbox and then clicking Save, the checkbox ...

issues with updating a MongoDB collection

One challenge I'm facing with my social media app is that I have two separate collections - one for users and the other for user posts. When I update information in a user's collection, it should also reflect in the corresponding posts (as the po ...

Is it possible to target the last child element in CSS without relying on nesting

Is there a way to select the very last child of an element and apply a specific class without using nesting? For instance, how can I target only the final div in the structure below, nothing more and nothing less. <body> <div class="very-last- ...

Element Not Adjusting to Content Size

I am encountering an issue with my div. I have floated an image to the right and placed my text beside it. My aim is to create a div with a linear gradient, however, the div ends up filling the entire page. How can I make my div adjust to fit only its con ...

Unable to retrieve the string contained within an element - JavaScript object literal

I am currently facing an issue where I am attempting to retrieve the text content of two div elements with classes .class-date and .class-time, but I keep encountering an Uncaught TypeError stating "e.siblings is not a function". I believe this may be a ...

Chrome not loading all the videos on a single page

Currently, I am working on a project that involves loading multiple videos on a single web page. The code snippet I am using looks like this: <div class="video_content left"> <span style="font-weight:bold">1</span> <video wi ...

Retrieve data from external URL using API

I am encountering a captchas page when attempting to retrieve JSON data from a URL through my API. Even though I am trying to access an array of JSON data containing openPrice, highPrice, price, and lowPrice, all I seem to get is a captcha form instead of ...

Incorporating a partial view within a view through AJAX requests

I am attempting to update a partial view within a view upon form submission, but I am facing issues where the partial view renders as a normal view instead. Can anyone help me identify the mistake in my code? Controller: public ActionResult ChangeHeatNam ...

Express.js session management -- Ensuring sessions are created exclusively for authenticated users

I've implemented the express-session Node module to handle secure session cookies. // To ensure certain requests require an active session, this code sets up a secure session cookie app.use(expressSession({ secret: "wouldn'tyouliketoknow", ...

Remove specific data from jQuery datatables using data attribute

My jQuery datatable is loaded with data from a database without any filtering by default, providing all the necessary information for users. In addition to the built-in search functionality of jQuery datatables, I have incorporated custom search input fiel ...

Transmitting client-side Javascript data to backend server using Express

I am trying to fetch data from my frontend using the DOM and send it to the backend through Express but I'm unsure of how to proceed. I have used a POST method to console.log the data, but now I need help retrieving it in my Express backend. (The cons ...