i was trying to print dynamic div html element using printElement() function but when i got problem…my code as follows
$("#btnPrint").click(function () {
if (ImgPath != '') {
sHtml = "<div id='dvPrint'><table>";
sHtml += "<tr><td>" + "<img src='" + ImgPath + "' border='0'/>" + "</td></tr>";
sHtml += "<tr><td>" + $('#lblTxt').html() + "</td></tr>";
sHtml += "</table></div>";
alert($('#dvPrint').html());
$("#element").printElement('#dvPrint');
}
else {
alert("Image not found for print");
}
return false;
});
when i just alert alert($('#dvPrint').html()); it show nothing. then how printElement() can work. i can append my dynamic div into body….i just need to generate div and print the content inside it by jquery…….i need help. thanks
You just formatted html string and didn’t append it to the DOM. You cant find it using
$('#dvPrint'). Use$(sHtml).html()to get the formatted html.And as a result print will be:
$(sHtml).printElement();