Scrolling issue while appending jQuery to a div within another div

After utilizing an AJAX request to pull in JSON content, I encountered an issue where appending it to a nested div resulted in an inactive scrollbar - it appeared but could not be used.

<style>
.tbox {
    width:440px;
    height: 500px;
    background-color:white;
    border:1px solid #E8E8E8;
    border-color:rgba(0,0,0,0.1);
    border-radius:5px;
    position:relative;
    -moz-box-shadow:3px 3px 14px #000;
    -webkit-box-shadow:3px 3px 14px #000;
    box-shadow:3px 3px 14px #000;
    margin:20px 0 0 50px;
    overflow: hidden;
}
.tbox .tbox-header {
    padding:12px;
    border-bottom:1px solid #E8E8E8;
    border-bottom-color:rgba(0,0,0,0.1);
    width: 100%;
    height: auto;
    overflow: hidden;
}
h1.ttitle {
    font-size:18px;
    line-height:18px;
    font-weight:bold;
}
.tbox .tbox-body {
    width: 100%;
    height: auto;
    overflow-x:hidden;
    overflow-y: scroll;
    position: relative;
}
ol {
    list-style-type:none;
    padding:2px;
}
ol li {
    clear:both;
    border-bottom:1px solid #E8E8E8;
    border-color:rgba(0,0,0,0.1);
    margin-bottom:15px;
    overflow:hidden;
    width:auto;
    height:auto;
}
</style>
<div class="tbox">
    <div class="tbox-header">
        <h1 class="ttitle">My Title</h1>
    </div>
    <div class="tbox-body">
        <ol>
        </ol>
    </div>
</div>

<script>
$.ajax({
    type: "GET",
    url: "[my PHP api]",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
        $.each(data, function (i, t) {
            $('.tbox-body ol').append(t.content);
        });
    }
});
</script>

When attempting to append the content to the nested div .tbox-body, the scrollbar remains inactive. However, if I remove the two nested classes (.tbox-header and .tbox-body) and directly append to .tbox, everything works as expected. Modifying the overflow-y properties of .tbox to auto or scroll does not seem to resolve the issue.

Answer №1

The issue you're encountering stems from the tbox-body not knowing when to scroll. The tbox is currently set at a fixed height of 500px. A simple solution would be to calculate the available height of the tbox-tbody and adjust its height using CSS.

For a quick demonstration, if you modify the .tbox-tbody from:

height:auto;

to:

height:300px;

You should notice that it now scrolls properly. Setting a specific height on the tbox-tbody also removes the necessity for multiple instances of overflow:hidden on various elements. It's advisable to only specify the overflow property on the tbox-tbody.

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 results can be expected from a piped file stream?

Perhaps the wording of the question may not be perfect, but here is some additional context. With GridFSBucket, I am able to store a file in MongoDB and retrieve a download stream for that file. Here's my query: If I wanted to send that file back as a ...

Determine whether the string includes any character during keyup event

I'm currently working on implementing a live search feature on my website. I have managed to make it work where the input field and link title match, but it only matches complete words. I am wondering if there is a way to display results that contain ...

Is there a way to create a soft light blue backdrop for text using HTML and CSS?

Is there a way to create a light blue background effect behind text using HTML and CSS? You can view the image reference here ...

Creating HTML code can involve managing multiple tasks on a single line

I am currently extracting HTML code into R using webscraping techniques. One issue I face is that sometimes multiple tasks are written on a single line, making it difficult to parse and format properly. My goal is to neatly organize the tasks so that each ...

Create a stylish card layout using Bootstrap featuring a 3D icon design

I am currently working on accomplishing this layout using Bootstrap 4 along with some custom CSS styles. https://i.sstatic.net/t3tot.png This is the code I have implemented so far: <div class="container"> <div class="row"> ...

Trying to understand the strange behavior of HTML parsing with jQuery in Javascript and Firefox

I have been working on a script to parse an HTML page using jQuery. The script runs smoothly in Chrome, IE, and Safari, but I'm facing some unexpected behavior while testing it in Firefox (version 36.0.1). Here's the code snippet: $.ajax({ u ...

Get the ID dynamically from the input, avoiding any hardcoded values

Today I am using the id #klm as a click event in jQuery to display an alert message. You can view the code snippet here. I tried replacing the value #klm with $("input").first().val() in the click event, but it was not successful. You can see this attempt ...

Received null JSON data from the server

Hey everyone, I have a strange issue that I need help with. So here's the situation: I'm using a java script client-side to send a request to my C# Controller and expecting an integer back. However, the response.data is returning null. What&apos ...

Is there a way to retrieve all jQuery-portlet data from a webpage?

I need help with creating a button that opens a dialog displaying all portlet data, including the column ID they belong to. The dialog should show the information in this format: col1: portlet title: Title1 portlet content: The Content of Title1.. port ...

Position the middle character within a span that has the identical width and height

My goal is to align characters in the center of a span. CSS span{border-radius:10px; width:20px; height:20px; color:#fff; background:#cc0000; text-align:center; line-height:20px; display:block;} HTML <span>+</span><br> <span>-&l ...

Reasons why the success function is not functioning properly

Learning J-QUERY and JavaScript is a process that I'm fairly new to. My issue lies with adding checks and alert messages to my forms which submit data to an asp page and call a T-SQL procedure. Although the process works, I struggle with implementing ...

make the width of the table cell as compact as can be

I have a table that spans 100% of the width, and I'm wondering how I can set the width of columns 2 and 3 to be as small as possible without causing the content to break. I tried adding a specific width style, but I know this is not recommended for r ...

Steps to designing 3 div elements containing portrait images in a row that are responsive using bootstrap

I'm facing a bit of a challenge trying to display 3 images in a row with a responsive layout using bootstrap. It seems like it should be easy, but I find it tricky. My goal is to create a page on my website that looks similar to this example - https: ...

When returning to the page, Vue reactivity experiences a hiccup

Using a basic binary variable called Vue named binary_state, I control the class of an element known as "controlled_element" in this discussion. This "controlled_element" has two classes, "class_true" and "class_false," depending on the value of binary_sta ...

I am currently working on a website project where I am looking to access and read a local JSON file using JavaScript

info = {"items": [ { "title": "example 1", "author": "writer 1" }, { "title": "sdample 2", "author": "a ...

Hold off until the jquery ajax call has completed and then provide the result

Waiting for an ajax call to complete and return its value is what I need help with. function checkFileExists(url) { var result = false; $.ajax({ type: "GET", async: false, url: url, crossDomain: true, dataTy ...

What is the method to choose an invisible link without an identifier using Selenium WebDriver?

I am attempting to click on the link labeled 'User Requested'. This link only appears when hovering over the menu. This is the HTML code: <ul class="k-widget k-reset k-header k-menu k-menu-horizontal" id="menu" data-role="menu" tabindex="0" ...

Tracking the progress of file uploads using Ajax

Currently, I am working on integrating file upload using Ajax and Php on my local Apache server. This is strong text. $('.uploadButton').click(function(){ var formData = new FormData($(this).closest('.fileUploadFor ...

Is it necessary to save the details of a specific position in local storage when sliding?

Currently, I am in the process of replicating a webpage design from . I have written the code for the functionality where images and phrases change on every slide. There are three different phrases and images that are being displayed, and my goal is to sto ...

Tips for grabbing a single line of text within a div element

After researching similar posts on Stack Overflow, I have not found a solution to my specific query. Imagine having some text enclosed within a div with an arbitrary width. Is there a way to programmatically capture and manipulate individual lines of this ...