Add Print Button for Selected or Particular Matter from Your Website using ID not Onclick | How To

Print Selected Matter

If You Want To Add A Print Button for Print Only Selected Matter when clicking Button, but Sometimes onclick method Remove automatically from HTML Edit Mode Page or You have Already created Template to Print selected Text but not word on Button.
So follow These Steps and Replace your “onclick” function to “ID”.

Button

Onclick Function:-

<button onclick="myFunction()">Your Button Name</button>

but Sometimes automatic remove onclick=”myFunction()”.

Button via ID:-

<button id="tkSpl">Your Button Name</button>

its tested in wordpress website and blogger website.

How To Use

>> Pasted This JavaScript code in Your Theme

document.getElementById("tkSpl").onclick = function() {tkSpl()}
function tkSpl() {
var backup = document.body.innerHTML;
var divToPrint = document.getElementById("printmatter").innerHTML;
var popupWin = window.open();
popupWin.document.open();
popupWin.document.write(divToPrint);
popupWin.window.print();
popupWin.document.close();
}

>> Then Add id=printmatter in your DIV Tag which You matter You Have To Print.

If you have wordpress website and this code is not working, So try this another code – click here

Conclusion

Try This Method in Your Website, When Automatic remove onclick function from your webpage Button.