Home > Web Front-end > CSS Tutorial > How to Efficiently Determine the Height of Hidden Elements in jQuery 1.4.2?

How to Efficiently Determine the Height of Hidden Elements in jQuery 1.4.2?

Linda Hamilton
Release: 2024-12-16 21:05:12
Original
411 people have browsed it

How to Efficiently Determine the Height of Hidden Elements in jQuery 1.4.2?

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 : "");
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template