My print function button doesn't seem to work upon clicking. The print view page does not show.
Here is the html code:
<button class = "hidden-print" id = "print-click">Print New Orders</button>
Here is the js code:
function printNewOrders(){
window.print();
$("#print-click").click(printNewOrders);
}
asked Apr 14, 2016 at 17:00
Pocholo Delenela Mendoza
178 bronze badges
1 Answer 1
Your click event won't be bound unless you call the function printNewOrders. Even though if you call it the page will be printed without user's intervention. So change your code like below,
function printNewOrders(){
window.print();
}
$("#print-click").click(printNewOrders);
DEMO
answered Apr 14, 2016 at 17:02
Rajaprabhu Aravindasamy
67.2k17 gold badges107 silver badges133 bronze badges
Sign up to request clarification or add additional context in comments.
6 Comments
Rajaprabhu Aravindasamy
@PocholoDelenelaMendoza Check the demo attached with this answer. Did you include jquery in your page? Are you seeing any errors?
Pocholo Delenela Mendoza
I did not include jquery. No errors as well when inspecting element. The function just does not work. Is there any more solutions?
Rajaprabhu Aravindasamy
@PocholoDelenelaMendoza
$("#print-click").click(printNewOrders); This part will not work without jquery. If you want a non-jquery solution. you can use this jsfiddle.net/j8vfftpa/1 Pocholo Delenela Mendoza
The button still does not function. The print media view still does not come out upon clicking.
Rajaprabhu Aravindasamy
@PocholoDelenelaMendoza Is your site live? Or can you reproduce your issue in a fiddle?
|
default
$("#print-click").click(printNewOrders);out of the function.$("#print-click").click(printNewOrders);to$(document).on("click", "#print-click", printNewOrders);