Yuriy Mayorov
Yuriy Mayorov

Reputation: 971

how to use append after load. jquery

All. I am using jquery. And I want to append element into loaded html from file (using "load"). It doesn't work.

Is it possible, to use append after load?

Upvotes: 0

Views: 2349

Answers (2)

suomi-dev
suomi-dev

Reputation: 868

yes it is:

    $("#myDiv").load("/Controller/View", function (responseTxt, statusTxt, xhr) {
    if (statusTxt == "success") {
        $("#myDiv").append('<input type="hidden" name="hdnText" value="8" />');
    }
    if (statusTxt == "error")
        alert("Error: " + xhr.status + ": " + xhr.statusText);
});

Upvotes: 1

aziz punjani
aziz punjani

Reputation: 25796

You can use $.get instead. $.load is specifically for loading the returned data into an element such as a div.

$.get('url', function( data ){
    $('#your-div').append( data ); 
});  

Upvotes: 1

Related Questions