When the previous div is visible and has a greater height, the div does not scroll

When the div containing D1, D2... data exceeds the size of the div, ideally a scroll bar should appear. However, if I click on the Filter link, the size of the D1, D2... data div should increase. Since my data is dynamic, specifying a fixed height for the DIV is not possible.

$(document).ready(function(){
$("#filter-text").click(function(){
   var  a =  $("#filter-option").toggle();
if(a.css("display")=="block"){
$("#data").css("height","80%");
}else{
$("#data").css("height","96%");
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
   <div style="width:500px;height:500px;background-color:#efefef;position:absolute;">
<div id="parent" style="position:relative;">
<div id="filter" style="border:1px solid #00FF00;float:left;overflow:auto;width:100%;">
<div id="filter-text" style="cursor:pointer; color:#0000ff;height:4%;" >Filter</div>
<div id="filter-option" style="height:80px;">
This content will be hidden when filter is clicked
</div>
</div>
<div id="data" style="border:1px solid #0000FF;overflow:auto;float:left;width:100%;max-height:80%;position:relative;">
<table>
<tr><td>This div must have a scrollbar if its height is higher than its parent</td></tr>
... (remaining table rows from D1 to D20)
</table>
</div>


</div>
</div>

Answer №1

Take a look at this JSFiddle link.

This resource might offer some assistance.

 <div id="data" style="border:1px solid #0000FF;overflow:auto;position:absolute;bottom:0;top:100px;">

By adjusting the positioning of the #data div to fix it at the top and bottom, you should be able to see the scroll function in action.

Answer №2

$(document).ready(function(){
    $("#filter-text").click(function(){
        $("#filter-option").toggle();
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<div style="width:500px;height:500px;background-color:#efefef;">
            <div id="parent" style="position:relative; height:100%;">
                
                <div id="filter" style="border:1px solid #00FF00;position:relative;overflow:auto; /*height:20%;*/">
                    <div id="filter-text" style="cursor:pointer; color:#0000ff;" >Filter</div>
                    <div id="filter-option" style="height:80px;">
                        This content will be hidden once Filter is clicked
                    </div>
                </div>
                <div id="data" style="border:1px solid #0000FF;overflow:auto; height:80%;">
                    <table>
                        <tr><td>This div must have scroll bar if its height is higher than parent</td></tr>
                        <tr><td>D1</td></tr>
                        <tr><td>D2</td></tr>
                        ...
                        <tr><td>D18</td></tr>
                        <tr><td>D19</td></tr>
                        <tr><td>D20</td></tr>
                    </table>
                </div>
                <div sytle="clear:both"></div>
            </div>
        </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

In JavaScript, obtaining the URL of an iframe after it has been reloaded is not functioning correctly in Chrome and Safari browsers

I have been developing a phaser game that will be integrated into a website through an iframe. The game has the capability to support multiple languages, and we have decided to determine the language based on the site from which the game was accessed (for ...

Attempting to enlarge an image by hovering over it proves to be futile

Currently, I am exploring CSS and attempting to enlarge 2 images when they are hovered over. Unfortunately, the desired effect is not working. .imagezoom img { position: relative; float: left; margin: 50px 5px 0px 42px; border-color: rgba(143, 179, 218, ...

Incorporate a "Back" button following the removal of the navigation bar in a Meteor-Ionic

When working on a Meteor-Angular-ionic app, I encountered a situation where I needed to hide the nav-bar in a template to create a full-screen view using the following code: <ion-view hide-nav-bar="true"> However, I then faced the challenge of addi ...

What is the best way to create two fields side by side within a single row?

I'm struggling to merge the data array of two different identity types into one row as a field. Here's the code I've written: import React from 'react' import {Form,Field,ErrorMessage,Formik} from 'formik' import * as yup ...

Implementing jQuery's live() method to handle the image onload event: a guide

Looking to execute a piece of code once an image has finished loading? Want to achieve this in a non-intrusive manner, without inline scripting? Specifically interested in using jQuery's live() function for dynamically loaded images. I've attemp ...

Handling Pop-up Windows in Puppeteer using NodeJS

During my training exercises, I encountered a situation where I needed to click on a button that opens an internal "pop-up" from a specific page on Amazon. Unfortunately, Puppeteer was unable to detect this pop-up, making it difficult for me to interact wi ...

Ensuring the child div's height does not overflow beyond the parent div

When dealing with a parent div and a child div, both having different heights, how can I specifically retrieve the height of the portion of the child div that is within the boundaries of the parent div? Using document.getElementById("id").style.height prov ...

Toggle the input box by clicking the button

How do I show or hide the input box (blue square) when I click the search button (red square)? Link Image I attempted to create the transition in CSS and also experimented with JavaScript, but the JavaScript part confused me. Here is what I tried: $(" ...

Room on the edges of a div that is positioned absolutely

I would like to create a space of 10px on each side of the #in div, similar to this layout: Check out the code here - live demo: html <div id="out"> <div id="in"></div> </div> css #out { width: 700px; height: 40px; back ...

The functionality of the datepicker ceased to work once an HTML form was appended, which was triggered

Here is a related question to the previous one: After triggering a new HTML form by changing data in one of its select input fields, I successfully replace the form using AJAX response and jQuery binding. Once I change the input value to the first input f ...

Tips for eliminating the left and bottom border in a React chart using Chart.js 2

Is there a way to eliminate the left and bottom borders as shown in the image? ...

Passing 2 props to the parent component using the same function in React

Is there a way to set the state and close the modal simultaneously in a child component by passing props back to the parent? It seems that only one action works at a time, even though they both work independently. How can I resolve this issue? CHILD COM ...

Using a twig loop to display just a single table cell

The following twig loop is used to generate data: {% for reservationDate, rooms in data.pricingTable %} <tr> <td> {% for room in rooms %} <tr> <td ...

Issue with the scope causing global variable not to update when button is pressed

I am facing an issue with a declared variable and jQuery code that is supposed to store a form's value as the value of that variable when a button is clicked, and then execute a function. var verb = ""; $( "#submit" ).click(function() { verb = $(& ...

Can I safely refresh the browser during integration test specifications?

We currently have a set of Protractor and Jasmine specs for our AngularJS project. Is it acceptable to use the following code snippet to clean up things between specs: afterAll(function(){ browser.restart(); } Your insights on this matter would be gre ...

What is the best way to translate a string containing Angular bindings using Angular Translate?

I am looking to implement localization in an app I am currently developing using Angular Translate. Here is a snippet of my code: <p class="md-caption" translate="vm_stats_score"></p> My goal is to assign this to an ID required by Angular Tr ...

How can CSS be used to select and style all elements within a <p> tag?

My fashion sense is specific: #style p { padding:10px; } I'm unsure which elements will be nested inside the paragraph. Is there a method to apply 10px padding to all elements within that paragraph? Can it be done like this? #style p everything ...

Utilizing jQuery for replicating form values specific to each column

Previously, I have utilized jQuery to transfer billing addresses to shipping addresses. However, when dynamically generating form rows with various PHP values, how can the form be configured so that upon checking a box, the recommended quantity of an item ...

Is there a way to access a JSON node dynamically without relying on the eval function?

Path variables can be unpredictable, ranging from just a to a/b, and even a/b/c. My goal is to dynamically reach a node based on the path provided. The code snippet below achieves this, but I am open to exploring alternative methods that do not involve usi ...

JavaScript/jQuery Progress Bar for Tracking File Downloads

I've been working on a project that involves downloading multiple files as a single zip file using the JSZip plugin. However, during the download process, the browser freezes up and I'd like to implement a progress bar to indicate how far along t ...