How to Retrieve the Width of a Div Element in Jquery with Overflow Hidden

Is there a way to determine the width of a div that is inside another div with "overflow: hidden;"?

I attempted setting overflow to auto and then using $("#divselector").width(), but it seems to always provide the width of the parent div!

For example:

HTML:

<div id="content">
            <div id="item">content content content ...</div>
</div>

CSS:

#content
{            
    width: 760px;
    height: 100%;
    overflow: hidden;
    display: block;
    position: relative;
    cursor: move;
}

Note: It works in IE 6, but not in IE 8...

Answer №1

Typically, div elements will automatically adjust their width to fit their parent element.

However, when you float the items inside a div, they will no longer expand to fill the parent's width.

To address this, include the following style rules:

#item { float: left; }

To see how this rule functions, visit: http://jsbin.com/umabe/edit

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

Having trouble with the find method when trying to use it with the transform

In my code, I have three div elements with different values of the transform property assigned to them. I store these elements in a variable using the getElementsByClassName method and then try to find the element where the value of the transform property ...

Activate the parent navigation link when on sub-pages

I want to ensure that the parent navigation item is highlighted when a user is on a child page based on the URL. For example, if the user is currently viewing foo1-child and the parent is foo1, I need to apply the active class to Foo 1: http://foo.com/foo ...

finding the index of a particular checkbox in a list

I am working with a list of checkboxes that are dynamically created using JavaScript, each contained within its own separate div element. I need to determine the position number of a specific checkbox within all checkboxes sharing the same class within a p ...

The loop in Twitter Typeahead is configured to use the URL of the first field

I am facing an issue with my typeahead initialisation function. This function is meant to set remote URLs for all typeahead fields based on a data-url value, but it seems to be setting all fields to the URL of the first field. Even when I manually destroy ...

Acquire JSON data using a Bearer token

I am facing an issue with my getJSON script that normally outputs JSON strings. However, it seems to be failing when using a Bearer Token API. Even though I have included the Bearer Token in my HTTP Header like this: authorization: Bearer Mytoken I am no ...

Having trouble with input event listeners in JavaScript?

I've been attempting to trigger the keyup event using EventListener for an input tag, but it doesn't seem to be working and I'm unsure why. Here is the code I have: document.getElementById("ajax").addEventListener("keyup", function() { ...

Why do the checkbox values consistently appear as null after sending a post request with Ajax to a Controller?

When making an Ajax call to send data to a controller in my ASP.NET Core application, the function grabs a value from an input box and iterates through a div to collect the values of checked checkboxes into an array. The issue arises when the data is sent ...

I am having trouble sending the text of a selected list item from a dropdown menu to the controller from the view in MVC4. The controller is receiving a null value. Can someone please

This is my code snippet for creating a dropdown menu to select classes: <div class="dropdown"> <button class="btn btn-danger btn-lg dropdown-toggle" type="button"id="menu1" data-toggle="dropdown">Go To Class<span class="caret"></ ...

Retrieve a targeted table from a webpage through Ajax refresh

On a webpage, I have a table that has two different views: simple and collapsible. I want to be able to toggle between these views using a button click without the need to refresh the entire page. Below is the code snippet I am currently using: $(&apo ...

Guide on making a flowchart using CSS

I'm working on creating a CSS flow chart diagram and I've included an image below for reference. Might there be a straightforward method to achieve this? I've been scouring the web for examples, but I'm unsure of what terminology to use ...

What causes conflicts between CSS and HTML tables?

I'm currently working on designing an email ticket template that incorporates a small table for clients to easily view the subject and description of their ticket. The template was looking great until the table was inserted, causing a complete formatt ...

What is the best way to obtain the output of a JavaScript function on the server side?

I'm dealing with a JavaScript function that returns an array in this particular format: <script type="text/javascript"> function looping() { var column_num = 1; var array = []; $("#columns ul").not(" ...

Can the looping feature be applied to CSS?

I've been reusing the same CSS code multiple times, just changing the names each time. It feels repetitive to call the same CSS repeatedly with different names. I'm considering looping through it instead. Any suggestions? #block1{display:block; ...

What could be causing the TailWind CSS Toggle to malfunction on my local server?

While working on designing a sidebar for a ToDo page using Tailwind CSS, I encountered an issue with implementing a toggle button for switching between dark mode and light mode. In order to achieve this functionality, I borrowed the toggling code snippet f ...

Challenge with shifting list items

The issue arises when applying margin to any element within the product or slider div, causing all list items to shift downwards. .product-slider { margin-top: 16px; text-align: center; } .slide-item { list-style-type: none; display: inline; ...

Inject CSS values dynamically

I am currently working on dynamically setting the color of a div. To provide some context, let's examine the following: <!doctype html> <head> <link rel="stylesheet" href="style.css"> </head> <body> <div clas ...

How can I execute a basic query in jQuery or JavaScript based on a selected value that changes

After successfully retrieving the dropdown selection value with alert(selectedString) in this scenario, I am now looking to utilize that value for querying a table using mysqli and PHP. What is the best approach for querying a database table based on the ...

What is the best method for resetting the CSS style of a specific DOM subtree?

While working on a Chrome Extension, I encountered a problem where an HTML subtree and CSS style sheet injected into the original page were being affected by the original CSS. Despite my attempts to override the styles, it seemed unfeasible to manually set ...

Using Jquery to access the grandparent element

When I have code similar to what is shown below, an element contains within 3 layers: <span class="dropdown test1"> <span class="test2" type="button" data-toggle="dropdown">hello</span> <ul class="dropdown-menu test3" style="m ...

Displaying a loading indicator as content loads within the iframe

How to Display a Loading Indicator During Content Loading Within an iFrame: 1) When a postback or submit event occurs within a form inside the iFrame ...