Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS JQuery Position Selector is null on IE

I have a problem with my JQuery position() code. The code works perfectly on Chrome/Firefox but fails on IE.

The JS code is:

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 the HTML is:

<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>

Normal browsers returns the left and top values, and IE says:

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

Thanks in advance.

like image 270
Aviram Avatar asked Jan 24 '26 06:01

Aviram


1 Answers

I found the problem. The HTML header was:

<html dir="rtl">

And that's what caused the problem in my case. When I set to page to LTR it works also on IE.

Thanks.

like image 136
Aviram Avatar answered Jan 25 '26 23:01

Aviram



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!