How to print HTML content on click of a button Or a link?
I want to print some HTML content, when the someone clicks on a button.
Share
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Aviance School is one of the largest web solutions platform in India for developers to learn and share their programming knowledge and build their careers.
<!DOCTYPE html>
<
html>
<
head
>
<
title
>
Print the content of a div
</
title
>
<!-- Script to print the content of a div -->
<
script
>
function printDiv() {
var divContents = document.getElementById("avnc").innerHTML;
var a = window.open('', '', 'height=600, width=600');
a.document.write('<
html
>');
a.document.write('<
body
> <
h1
>Div contents are <
br
>');
a.document.write(divContents);
a.document.write('</
body
></
html
>');
a.document.close();
a.print();
}
</
script
>
</
head
>
<
body
style
=
"text-align:center;"
>
<
div
id
=
"avnc"
style
=
"background-color: purple;"
>
<
h2
>Avianceschool</
h2
>
<
p
>
</
p
>
</
div
>
<
input
type
=
"button"
value
=
"Print Me"
onclick
=
"printDiv()"
>
</
body
>
</
html
>