0

I am trying to get data from SoundCloud API. I do it successfully, but the problem is that the data I get are only saved inside the scope and the variable stays 'undefined' outside the scope. JSFiddle

$.fn.greenify = function() {

    var trackURL = this.text();
    this.empty();
    var title, id;
    SC.get('/resolve', { url: trackURL }, function (track) {
        title = track.title; //track title
        id = track.id;
    });
    $(this).text(title); // title is undefined
    console.log(title);

};

$( "a" ).greenify(); // Makes all the links green.
$( "div" ).greenify();

So each html element must get the corresponding track title as text. But that doesn't happen because $(this).text(title); applies nothing.

Any idea?

Dan JF
  • 55
  • 5

0 Answers0