The problem seems to be you are declaring trackDownloadLink
as a global variable, you need to declare it as a local variable to the populateDownloadLink
method by using var
to declare it.
If you use it as a global variable, assume you hover over link 1 then trackDownloadLink
will refer to the corresponding anchor element and an ajax request is sent to fetch the href
value, then before the ajax is completed you hover over link2 now the global variable trackDownloadLink
is referring to the anchor in link2 instead of link1 and then the first ajax returns, at this time in the ajax complete when trackDownloadLink.attr('href', data.results[0].trackViewUrl);
is executed trackDownloadLink
is referring to the second link instead of first.
var trackDownloadLink = jQuery(e.currentTarget).find('.itunes-download a');