Hwy does my iteration on a object not return the matched query, and instead returns the last item in said object

this code is meant to take anchors listed inside of a webpage and link them to titles based on there id which are "http://# ('titles')

but when query for the element to use for scrollintoview.() my query selects the last item in the object not the matching one


                $('.scrollToPosition').click(function (e) {
                    e.preventDefault();

                    url = $(this).attr("href"); //get element
                    console.log(url);

                    linkid = url.substring(url.lastIndexOf("#") + 1); //parse id attr
                    console.log('linkid =' + linkid, linkid.length);
linkTarget = $('.scrollTarget').find($('a').attr("id") === linkid);

destinations = linkTarget.prevObject;


destinations.each(function (i) {
    scrollTo =$(this).find( $('#' + currentLink) === [i]);
    console.log(i)
    return
})

this is what my console returns

Upvotes: 1

Views: 19

Answers (0)

Related Questions