.position () giving error - JQuery

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;
    });
});
    
asked by anonymous 02.08.2017 / 01:49

1 answer

1

You have not defined 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>
    
02.08.2017 / 01:55