Hadi Mostafapour
Hadi Mostafapour

Reputation: 2266

how append text and object at once with jquery?

i have 2 text node and 1 jquery object, i want append them into DOM, when i do this:

$('<div>')
.append("Ajax Failed, ")
.append($("<span>").addClass('counter').countDown({
    start:o.time,
         onEnd:function(){$.ajax(o.ajax);},
         onRetryEnd:function(){o.onFailed();}
 }))
 .append(" Seconds until resend request")
 .appendTo('#domElement').align({position:'absolute',parent:$('#domElement')});

it will prefect (Result: Ajax Failed, 6 Seconds until resend request), but i want append all this data at once, like:

 var counter = $("<span>").addClass('counter').countDown({
    start:o.time,
         onEnd:function(){$.ajax(o.ajax);},
         onRetryEnd:function(){o.onFailed();}
 });

 $('<div>').append('Ajax Failed, ' + counter + 'Seconds until resend request');

Result: Ajax Failed, [object object] Seconds until resend request.
is possible do it at once and how?

Upvotes: 1

Views: 73

Answers (1)

ubik
ubik

Reputation: 4560

That is happening because of the plus signs in the last line. Something like:

 $('<div>').append('Ajax Failed, ', counter, 'Seconds until resend request');

Should work.

Upvotes: 3

Related Questions