JQuery Firefox error finding position () DIV

I ran into a strange problem with firefox, I have a DIV tag with ID = "popup_layer". I use jQuery to find this div that works fine:

var rightPosition=$j("#popup_layer")

But when I try to find the DIV position:

var rightPosition=$j("#popup_layer").position().left; 

In Firebug, I get the following exception:

[Exception ... "Failed to convert JavaScript argument arg 0 [nsIDOMViewCSS.getComputedStyle]" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: http: // localhost: 20094 / Scripts / CombineJS.ashx? JSFiles? /Scripts/jquery-1.2.6.min.js;%20%20%20%20/Scripts/PDP/newModalBox.js;%20%20%20%20/Scripts/CookieHelpers.js;%20%20% 20% 20popupLayer.js;% 20% 20% 20% 20 / BE / Scripts / scripts.js ; :: anonymous :: line 23 "data: no]

+3
source share
2 answers

For some reason, when I delete a style in my div, it starts working

<div id="popup_layer" style="display:none;">

For

<div id="popup_layer">

totally strange!

+1
source

You cannot get the dimensions or position of a DOM element with display:none. By definition, an element should not exist on the page, so it does not take up space.

I suggest that you first leave your element visible, having the desired dimensions, and then applying the " display:none" after you do it.

Alternatively, you can use <instead visibility:hidden.

+3
source

Source: https://habr.com/ru/post/1715112/


All Articles