user3024007
user3024007

Reputation: 283

Getting list item position()

I'd like to get the position of a list item but I'm getting 0 in both cases...

// html
<ul id="menu">
    <li id="itm1">ITEM ONE</li>
    <li id="itm2">ITEM TWO</li>
</ul>

// css
#menu {
    position:absolute;
    top:5em;
    left:1em;
}

// JS
clickMenuItem = function(t) {
    var pos = $('#' + t).position();
    var y = pos.top;
    console.log('y : '+y)
}

clickMenuItem('itm1');
clickMenuItem('itm2');

How do properly retrieve the position in this case?

Upvotes: 1

Views: 907

Answers (1)

Tekkzz
Tekkzz

Reputation: 638

You can do with jquery at the $(document).ready(function(){ /*your code */ });:

$("li").click(function(e){
    var pos = $(this).position();
});

just log this variable then..

Upvotes: 2

Related Questions