CSS jQuery Position Selector null for IE

I have a problem with jQuery position () code. The code works fine on Chrome / Firefox, but does not work on IE.

JS Code:

function myFunc() {

var x = $("#menu li.active");
if (x == null)
  alert('x is null');
else  
  alert(x.position().left + " " + x.position().top);
}

$(document).ready(function() { myFunc(); });

And HTML:

<ul id="menu">
    <li class="active"><a href="test.php"><span>Test 1</span></a></li>
    <li><a href="test2.php"><span>Test 2</span></a></li>
</ul>

Regular browsers return the left and top values, and IE says:

Message: 'position (). left 'is null or not an object

Thanks in advance.

+3
source share
1 answer

I found a problem. HTML header:

<html dir="rtl">

And what caused the problem in my case. When I set the page to LTR, it also works in IE.

Thank.

+3
source

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


All Articles