JsCoder
JsCoder

Reputation: 1733

JQuery measuring position of a hidden element

Is there a way to get $element.position() working for a hidden (i.e. display:hidden) element?

Upvotes: 1

Views: 2889

Answers (3)

mr_app
mr_app

Reputation: 1312

Just try

mypos = $('#myelement').css({
  visibility: 'hidden',
  display: 'block'
}).position();

Upvotes: 2

Beetroot-Beetroot
Beetroot-Beetroot

Reputation: 18078

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.

Upvotes: 2

DoXicK
DoXicK

Reputation: 4812

'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

Upvotes: 1

Related Questions