Ticket #9417 (closed bug: duplicate)
dimensions are unretrievable on an element whose parent is hidden and does not have any styles set
| Reported by: | samuel | Owned by: | |
|---|---|---|---|
| Priority: | low | Milestone: | 1.next |
| Component: | dimensions | Version: | 1.6.1 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: | #9300 |
Description
<span id="test" style="display:none;">ffffff</span> $("#test").width() OK
but <div id="mydiv" style="display:none;"> <span id="test"> ffffff</span> </div>
$("#test").width() is 0 Error
I can`t get the width when the span in a hidden div
Change History
comment:1 Changed 2 years ago by timmywil
- Priority changed from undecided to low
- Status changed from new to open
- Version changed from 1.4.2 to 1.6.1
- Component changed from unfiled to dimensions
- Blocked by 9300 added
comment:2 Changed 2 years ago by Mike Sherov <mike.sherov@…>
I suppose instead of doing jQuery.swap() on the element itself, we could jQuery.swap all the "display:none;" parents of the element as well... that's a brute force approach, but it may work?
comment:3 Changed 2 years ago by timmywil
- Summary changed from a bug on "width()" to dimensions are unretrievable on an element whose parent is hidden and does not have any styles set
comment:4 Changed 2 years ago by dmethvin
- Status changed from open to closed
- Resolution set to duplicate
I think we decided this was too gruesome to handle long ago. Mike Sherov's method will often work but would potentially be very slow in the general case. I don't think we'd want to be an enabler of bad practice.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

http://jsfiddle.net/timmywil/S8H2w/1/
It would be great if we could get this working, but it's not easy.
Related to #9300. This is different in that this element does not have a width set in its styles to retrieve as a fallback.