Increase the height of a div dynamically in HTML during program execution

Within my datagrid, there exists an expandable/collapsible section above the content (see Picture 1 https://i.sstatic.net/N68Rl.png). Upon expanding the content, a scroll bar appears within the datagrid element to display the data (see Picture 2 https://i.sstatic.net/QxVfI.png).

To potentially resolve this issue, is it feasible to dynamically update the maximum height by adding the current height with an additional 30px? If so, how can this be achieved?

.panelGrid {
  background-color: white;
  max-height: 0;
  overflow: auto;
  transition: max-height 0.2s ease-out;
  border-left: 1px solid gray;
  border-right: 1px solid gray;
  border-bottom: 1px solid gray;
}

Below is the relevant code snippet:

<asp:Panel Style="font-size: 14px;" Visible='<%# Eval("Description").ToString() == "Discharges" %>' runat="server">

    <label class="collapsible" style="font-size: 10px;">Check List</label>

    <div class="content text-left">

        <ul>
            <li><a href="../Iframes/IFDC.aspx" target="_blank" runat="server" onclick="window.open('../Iframes/IFDC.aspx', 'InstitutionalFUllCheckListWindow','width=1680,height=1300, scrollbars=1,resizable=1'); return false;">Institutional – Pre Settlement Checklist</a></li>
            <li><a href="../Iframes/DMARDFC.aspx" target="_blank" runat="server" onclick="window.open('../Iframes/DMARDFC.aspx', 'DischargeMortgageCheckListWindow', 'width=1680,height=1300, scrollbars=1,resizable=1'); return false;">Institutional – Post Settlement Checklist</a></li>
            <li><a href="../Iframes/FFDC.aspx" target="_blank" runat="server" onclick="window.open('../Iframes/FFDC.aspx', 'FundFUllCheckListWindow', 'width=1680,height=1300, scrollbars=1,resizable=1'); return false;">Private– Pre Settlement Checklist</a></li>
            <li><a href="../Iframes/PDC.aspx" target="_blank" runat="server" onclick="window.open('../Iframes/PDC.aspx', 'PartialDischargeCheckListWindow', 'width=1680,height=1300, scrollbars=1,resizable=1'); return false;">Partial – Pre Settlement Checklist</a></li>
        </ul>

    </div>

</asp:Panel>
                        

Answer №1

My solution involved implementing a JavaScript function to monitor when the collapsible class is clicked and then updating the maximum height if it matches the specified name.

  <script>
        var coll = document.getElementsByClassName("collapsible");
        var i;

        for (i = 0; i < coll.length; i++) {

            coll[i].addEventListener("click", function () {
                this.classList.toggle("active");
                var content = this.nextElementSibling;
                if (content.style.maxHeight) {
                    content.style.maxHeight = null;
                } else {
                    content.style.maxHeight = content.scrollHeight + "px";
                }
                if (content.id == 'DischargeCheckList') {
                    document.getElementsByClassName("panelGrid")[19].style.maxHeight = (document.getElementsByClassName("panelGrid")[19].scrollHeight + document.getElementById("DischargeCheckList").scrollHeight) + "px";
                }
            });
        }
    </script>
<div class="panelGrid">
  <asp:Panel Style="font-size: 14px;" Visible='<%# Eval("Description").ToString() == "Discharges" %> ' runat="server">

    <label class="collapsible" style="font-size: 10px; height: 30px">Check List</label>

    <div class="content text-left" id="DischargeCheckList">

      <ul>
        <li>
          <a href="../Iframes/IFDC.aspx" target="_blank" runat="server" onclick="window.open('../Iframes/IFDC.aspx', 'InstitutionalFUllCheckListWindow','width=1680,height=1300, scrollbars=1,resizable=1'); return false;">Institutional – Pre Settlement Checklist</a>
        </li>
        <li><a href="../Iframes/DMARDFC.aspx" target="_blank" runat="server" onclick="window.open('../Iframes/DMARDFC.aspx', 'DischargeMortgageCheckListWindow', 'width=1680,height=1300, scrollbars=1,resizable=1'); return false;">Institutional – Post Settlement Checklist</a></li>
        <li><a href="../Iframes/FFDC.aspx" target="_blank" runat="server" onclick="window.open('../Iframes/FFDC.aspx', 'FundFUllCheckListWindow', 'width=1680,height=1300, scrollbars=1,resizable=1'); return false;">Private– Pre Settlement Checklist</a></li>
        <li><a href="../Iframes/PDC.aspx" target="_blank" runat="server" onclick="window.open('../Iframes/PDC.aspx', 'PartialDischargeCheckListWindow', 'width=1680,height=1300, scrollbars=1,resizable=1'); return false;">Partial – Pre Settlement Checklist</a></li>
      </ul>

    </div>


  </asp:Panel>
</div>

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

Database stores line breaks in a structured format

As I work on creating a posts section for my readers, I have encountered an issue. When a user adds a new post, it gets saved into the database in this format: Some say the world will end in fire,<br /> Some say in ice.<br /> From what I’ve ...

When I add text to div boxes, they begin to drift downward

After creating four div boxes with content, I encountered an issue. Initially, when inserting filler text, everything seemed fine. However, as soon as I started adding actual content into the first box, the other three boxes shifted downwards by the same a ...

Build a Container Div using DOM/XPATH techniques

I have just initialized a new DOM XPATH OBJECT. After performing several operations, I saved my result using SaveHtml $String[] = $dom->saveHTML(); Next, I placed the content into a file. file_put_contents($filename, $string); The HTML Structure l ...

Storing Documents on Your Device

I've been working on a project to create a web page that provides links to online PDF files. When you click on these links, the file should be saved locally and its name/path added to local storage. I then aim to display all the saved files by iterati ...

Having trouble resolving the signature of a class decorator when invoked as an expression with @Injectable in Angular

Error Message: Unable to resolve the signature of a class decorator when called as an expression. The argument type 'ClassDecoratorContext' is not compatible with the parameter type 'string | symbol | undefined'. After creating a book ...

Box-free calendar dash component

Encountering an issue within my application dashboard, here's a direct screenshot: https://i.stack.imgur.com/sEMrM.png The problem is that the Calendar days are extending beyond the borders of the calendar box. To implement this, I simply utilized ...

JavaScript's addition of CSS animation not functioning as intended

I am facing an issue with a web page utilizing Bootstrap 5. The webpage consists of one element stacked on top of another. My goal is to fade-out the top element after a certain period. Here is what I have tried: HTML <div id="host" class=&qu ...

When the child content surpasses the height of the parent, you can scroll within an overflow:visible; div

My sidebar navigation menu includes children and sub-children that are revealed on hover. You can view a simplified version of it in this jsfiddle link: https://jsfiddle.net/s096zfpd/ Although the example provided is basic, my main concern arises when the ...

Having trouble aligning my CSS form correctly

The issue is with the alignment of the second row of textbox elements under the "Add Equipment" section on this page: While organizing the code in Dreamweaver, the elements line up correctly. However, when viewed in Google Chrome, they shift to the second ...

Creating and adding nested div elements with the power of JavaScript

My goal is to utilize JavaScript for updating the CSS layout as the webpage loads. Below is the code I have been working on: var container = 0; // Total UI Container var containerTitle = 0; // Title Container var article = 0; var articleTitle = 0; var ...

Adjust the placement of the outcome on the table using PHP

I am attempting to display 7 results in a table (image 1) and need to adjust their positioning. In the array, Mon = 1 and Sun = 7. Where there are no values, I want them to display as $0. However, I am struggling to move them to the correct spot on the ta ...

Prevent touching the pseudo content of an element

My issue involves a toggle button component where I have utilized the ::before pseudo class to add text. The problem arises when clicking on the text within the toggle button causes the button's state to change. How can this be prevented? Here is the ...

The div is not completely encased by the fieldset

I have utilized fieldset to generate a titled border around a div. Here is the code snippet: <div class="form-group col-xs-12"> <fieldset class="field_set col-xs-12"> <legend style="font-weight:bold;font-size:20px"> ...

How can I conceal the contents of a webpage until the entire page has finished loading before revealing them?

Is there a way to delay displaying my login template until all elements are fully loaded? Currently, when I visit the site, the template appears first followed by fonts and other components. I want to ensure that nothing is shown to the user until the enti ...

Designing tables and image galleries using HTML, CSS, and jQuery: A guide

How can I easily transform tabular data into thumbnails with the click of a button? I need a 2-view system that switches between table and thumbnail views without including image thumbnails. I welcome any creative suggestions! :) Examples: ...

Prevent the overlap of text by controlling the positioning of a div element

Below is a simplified version of the layout I'm working with: <div style="position: relative; width:600px;"> <p>Content with unknown length, but very lengthy</p> <div>Content with unknown height</div&g ...

HTML/JavaScript - Ways to show text entered into an input field as HTML code

One dilemma I'm facing involves a textarea element on my website where users input HTML code. My goal is to showcase this entered HTML code in a different section of the webpage. How should I approach this challenge? The desired outcome is similar to ...

Vue's watch feature will not execute if the watched property remains unchanged during a page reload

<template> <!-- The navbar has a property for gender, the color of the navbar will change depending on the gender --> <!-- pass the props gender through a form submission and event --> <div class="nav-main" :class="{f ...

Removing the restriction on maximum width to 100% and allowing for automatic height adjustment

Within my project, I have implemented a CSS technique where all images within a container are set with the attributes max-width: 100%; and height: auto;. This is done to ensure that images scale down appropriately when the viewport and container size decre ...

Having difficulty centering an image in HTML?

I've been struggling to get the image (logo) centered on the top bar! I've tried using align-self: center;, display:block;, but nothing seems to work. It feels like I'm missing something here! Click here for the codesandbox link to view the ...