
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
How to set the page-break behavior inside an element with JavaScript?
Use the pageBreakInside property in JavaScript to set the page-break behavior inside an element. Use the auto property to insert page break inside an element. Use auto or avoid property value to automatically insert page break inside an element, if needed, or avoid a page break, respectively.
Note − The changes would be visible while printing or viewing the print preview.
Example
You can try to run the following code to return the page-break behavior inside an element with JavaScript −
<!DOCTYPE html> <html> <body> <h1>Heading 1</h1> <p>This is demo text.</p> <p>This is demo text.</p> <p id = "myFooter">This if footer text.</p> <button type = "button" onclick="display()"> Set page-break </button> <script> function display() { document.getElementById("myFooter").style.pageBreakInside = "auto"; } </script> </body> </html>
- Related Articles
- How to set the page-break behavior after an element with JavaScript?
- How to set the page-break behavior before an element with JavaScript?
- How to set the minimum number of lines for an element that must be left at the bottom of a page when a page break occurs inside an element with JavaScript?
- Usage of page-break-before, page-break-after, and page-break-inside properties in CSS
- How to include an external JavaScript inside an HTML page?
- How to include inline JavaScript inside an HTML page?
- How to set the padding of an element with JavaScript?
- How to set the height of an element with JavaScript?
- How to set the margins of an element with JavaScript?
- How to set the top position of an element with JavaScript?
- How to set the bottom padding of an element with JavaScript?
- How to set the left padding of an element with JavaScript?
- How to set the top padding of an element with JavaScript?
- How to set the right padding of an element with JavaScript?
- How to set the left margin of an element with JavaScript?

Advertisements