Andy Tanner
Andy Tanner

Reputation: 81

Putting load into variable

a quick question, how can I put the content of a loaded file into a JavaScript variable?

function myfunc(){
    $('.layer').load('content.txt');
}

I can access it with div class="layer", of course, but how can I also pass the result to a variable?

Thanks in advance!

Upvotes: 0

Views: 90

Answers (2)

Vivin Paliath
Vivin Paliath

Reputation: 95518

I imagine this is what you want:

var content = "";
$('.layer').load("./content.txt", function(responseText, textStatus, XMLHttpRequest) {
    content = responseText;

    /* do stuff with content */
});

Upvotes: 2

fcortes
fcortes

Reputation: 1368

Quick answer:

var plainText = $('.layer').content();

Upvotes: 1

Related Questions