Determining Height of Concealed Elements with jQuery
When encountering hidden elements within a hidden parent element, retrieving their height conventionally involves revealing the parent, obtaining the element's height, and then hiding the parent again. This process can appear inefficient.
Potential Solution for jQuery 1.4.2 Users
For jQuery 1.4.2 users, the following approach offers an alternative to the traditional method:
var previousCss = $("#myDiv").attr("style"); $("#myDiv").css({ position: 'absolute', // Optional if #myDiv is already absolute visibility: 'hidden', display: 'block' }); optionHeight = $("#myDiv").height(); $("#myDiv").attr("style", previousCss ? previousCss : "");
By temporarily modifying the element's style attributes, we render it visible but non-displayable. This allows us to retrieve the element's height while maintaining the illusion of concealment. Once the height is captured, we revert the CSS style to its original state.
The above is the detailed content of How to Efficiently Determine the Height of Hidden Elements in jQuery 1.4.2?. For more information, please follow other related articles on the PHP Chinese website!