Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the offset of a hidden element

How can I get the coordinates of a hidden element? offset() doesn't support the use for hidden elements. Any hints?

like image 897
Simon Avatar asked May 12 '11 06:05

Simon


People also ask

How do I show hidden elements in CSS?

You can hide an element in CSS using the CSS properties display: none or visibility: hidden . display: none removes the entire element from the page and mat affect the layout of the page. visibility: hidden hides the element while keeping the space the same.

Can hidden elements be clicked?

No. An element such as a hyperlink can't be clicked (and the link followed) if the visibility is set to hidden.

How do you hide an element but still take space?

Look, instead of using visibility: hidden; use display: none; . The first option will hide but still takes space and the second option will hide and doesn't take any space.

How do you show hidden elements in HTML?

Style display property is used to hide and show the content of HTML DOM by accessing the DOM element using JavaScript/jQuery. To hide an element, set the style display property to “none”. document.


1 Answers

If your element has had .hide() called on it, or if it's got display:none in css, the browser doesn't bother rendering it at all. In this case, the answer is not directly. In recent jQueries, you can't even get its width or height.

On the other hand, if you .show() an element, then .hide() it before an execution loop (an event firing through to when there's no more code to run for that event), the browser will be forced to relayout the page and you'll be able to get its offset between when it's shown and hidden, but it won't be forced to repaint, so your users won't see a blip, and you won't lose as much performance as you might think.

like image 161
issa marie tseng Avatar answered Sep 28 '22 08:09

issa marie tseng