I am trying to print the window. Code for html:
<!DOCTYPE html>
<html>
<head>
<title>Practising javascript</title>
<script src="practise.js"></script>
</head>
<body>
<p>Practising javascript</p>
<button id="submitButton">Print<button>
</body>
</html>
Code for javascript:
let printWindow = () =>{
window.print();
}
document.getElementById('#submitButton').addEventListener('click', () => {
printWindow();
})
But when I use onclick
on the button and use function with window.print()
as the functions body, it works. Why is it so?