skywind
skywind

Reputation: 962

Append/prepend not work with load? And some questions

I have two problems with append/prepend on JQuery. My code:

function toselect(f,d){
    $('#workcont').remove('h2').load('pages/' + f + '.html #' + d).prepend('<h2>Some text</h2>');
    calculate();
}

Div on default is clear <div id="workcont"></div>

Problems:

  1. prepend add code for a second and then disappears, why? (not hide! removed)

  2. remove('h2') don't remove added by prepend code. (if prepared wil be work) It's some function in my .js file.

  3. function calculate(); does not apply to loaded content. Use with live() also not work.

Upvotes: 0

Views: 202

Answers (2)

Pa.M
Pa.M

Reputation: 1402

load has a callback function , the reason is that load work async and hence the prepend add the html before load completes , you may try like this

function toselect(f,d){   

$('#workcont').remove('h2').load('pages/' + f + '.html #' + d, function(){

  $("#workcont").prepend("your html");
  calculate();

 });

}

Upvotes: 1

Gowri
Gowri

Reputation: 16845

try prepend in callback

function toselect(f,d){
    $('#workcont').load('pages/' + f + '.html #' + d,function(){
    $(this).remove('h2').prepend('<h2>Расчет стоимости</h2>');
    $('#workcont').calculate();
});

}

Upvotes: 4

Related Questions