Is there a way to get $element.position() working for a hidden (i.e. display:hidden) element?
            Asked
            
        
        
            Active
            
        
            Viewed 2,874 times
        
    1
            
            
         
    
    
        user1514042
        
- 1,899
- 7
- 31
- 57
- 
                    jQuery does not support getting the position coordinates of hidden elements or accounting for borders, margins, or padding set on the body element. – Ravi Y Jan 29 '13 at 12:45
- 
                    Makes sense, I just wanted a 'risk on me' type of solution. – user1514042 Jan 29 '13 at 12:49
- 
                    1If you know where the element is in your Dom tree, you could get position of its previous sibling or parent as required and then add the height/width of the said element to get your current position. However this may not be very easy in a fuildic layout. – Ravi Y Jan 29 '13 at 12:52
- 
                    1Just for the records: `display: hidden` is no valid css, either `display: none` or `visibility: hidden` – Simon Jan 29 '13 at 13:01
3 Answers
2
            
            
        You could try :
var pos = $element.show().position();
$element.hide();
Only in exceptional circumstances (some untimely interrupt by some process outside the current window/tab), will the element be momentarily rendered.
 
    
    
        Beetroot-Beetroot
        
- 18,022
- 3
- 37
- 44
1
            
            
        'display:none;' removes the element from the document so it does not have a position. You could try a quick 'display: block; visibility: hidden;', get the position, and hide it again.
Edit: This is explained on this question's page already: jquery: get the offset of hidden element
- 
                    I can still see the element as part of the visual tree, showing and hiding causes a flicker. I know why it's disable but in my case it's absolute safe to measure the top and height for a hidden element – user1514042 Jan 29 '13 at 12:47
- 
                    i know, it doesn't "remove" it from the document, but it does, as you noticed, remove it from the renderable elements. here is a better explanation and answer: http://stackoverflow.com/questions/5974323/jquery-get-the-offset-of-hidden-element – DoXicK Jan 29 '13 at 12:50
 
     
     
    