I've got a mysterious problem ... I try to take a part of an external page and put it in a variable. Here is the code :
$.get(url, function( data ) {
title = $(data).find('#layout-column_column-1 .journal-content-article').html();
}, 'html');
alert(title);
Using the javascript console on my browser (which is Chrome but that's the same on others), when I execute this code once, the alert(title)
returns "undefined". Then if I run it again (or just the line alert(title)
), I've got the result I expected.
Anyone has an idea ? :)
EDIT : sorry, the code I gave was not complete :
var a = $('a[target="_faq"]');
a.each( function() {
[...]
var title;
$.get('url', function( data ) {
title = $(data).find('#layout-column_column-1 .journal-content-article').html();
}, 'html');
$(this).attr('title', title);
}