.position() giving error - Jquery

Asked

Viewed 21 times

0

I’m getting the following error:

Uncaught ReferenceError: position is not defined

What’s wrong with the code?

$(document).ready(function () {
    $('.main_menu a').click(function () {
        var g = '.' + $(this).attr('href').replace('#','') + position.top;
        console.log(g);
        return false;
    });
});

1 answer

1


You did not set the variable: position

See the example taken from the jquery site

<script>
    var p = $( "p:first" );
    var position = p.position();
    $( "p:last" ).text( "left: " + position.left + ", top: " + position.top );
</script>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.