Search code examples
jqueryvariablesload

JQuery set variable with value from page


How can I insert a value to variable with:

$("#TEST").load("GET.php #Message_1");

An example of that:

var MSG = $("#TEST").load("GET.php #Message_1");

alert(MSG);

Solution

  • You need to get the value in the callback function:

    $("#TEST").load("GET.php #Message_1", function() {
        var msg = $(this).text();
        alert(msg);
    });