Categories: jQuery

jQuery – Get hidden element width

Share

In jQuery, when an element is not visible, the width() returns 0. But involving some CSS properties we can make jQuery think that the element is visible.

For example, you have the following HTML:

<div class="main">
<div class="sub" style="display:none;">John Doe</div>
<div class="sub" style="display:none;">Jane Doe</div>
</div>

If you want to get the hidden element width of “sub” class div then you can use the following tricks:

$( ".sub" ).css({ visibility: "", display: "" });
console.log($( ".sub" ).width());
$( ".sub" ).css({ visibility: "hidden", display: "block" });

Recent Posts

Guest Topic Name : Top 5 Must-Have Features Every Mobile App Needs to Succeed

Introduction Businesses understand the diverse requirements of mobile applications, which provide a competitive advantage. There…

2 hours ago

IoT Data Analytics: Ways to Gain Value from IoT Data

The Internet of Things (IoT) has recently changed the world. It links gadgets together and…

2 hours ago

The Rise of NFTs: Exploring the Impact of Non-Fungible Tokens on the Digital Economy

NFTs, or Non-Fungible Tokens, are revolutionizing the digital economy. These unique digital assets, authenticated through…

19 hours ago

Unveiling the Truth: Is the Spread of Sinus Infections a Myth or Reality?

Sinus infections, impacting approximately 31 million Americans each year, represent a significant health concern stemming…

2 days ago

Best Exercises To Reduce Weight & Keep You Stronger & Fitter!

No doubt that balanced weight is the key to wellness. So, when it comes to…

2 days ago

ARTIFICIAL INTELLIGENCE: Advantages And Disadvantages? Everything You Need to Know

Pros And Cons Of AI: Artificial Intelligence directly translates to conceptualizing and building machines that…

2 days ago