Why Split the <script> tag when Writing it within document.write() method in JavaScript? Last Updated : 14 Oct, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report In modern JavaScript development, the use of the document.write() method is discouraged due to its potential to cause performance issues and disrupt the parsing process of HTML. When the browser encounters a <script> tag, it pauses the parsing of HTML to execute the code within the script. Using document.write() during this phase overwrites the entire page content, which can break the current page structure and lead to incomplete execution, particularly if there are script tags within the document.write() output. As a result, better alternatives such as DOM manipulation methods should be used for dynamically modifying content.Note: This procedure have been used to include jQuery files only. Example 1: In this example, we will use <script> inside the document.write without splitting the tag. html <!DOCTYPE html> <html> <head> <style> body { text-align:center; } h1 { color:green; } </style> </head> <body> <h1>GeeksforGeeks</h1> <script> document.write( "<script><h1>GeeksforGeeks!</h1></script>"); document.write( "<p>A computer science portal for geeks</p>") </script> </body> </html> Output:Example 2: In this example we will use <script> inside the document.write by splitting the tag. html <!DOCTYPE html> <html> <head> <style> body { text-align:center; } h1 { color:green; } </style> </head> <body> <h1>GeeksforGeeks</h1> <script> document.write( "<script><h1>GeeksforGeeks!</h1></scr"+"ipt>"); document.write( "A computer science portal for geeks"); </script> </body> </html> Output: Comment More infoAdvertise with us Next Article JavaScript Course Understanding Code Structure in JavaScript S Shreyasi_Chakraborty Follow Improve Article Tags : Technical Scripter JavaScript Web Technologies Technical Scripter 2019 CSS-Misc HTML-Misc JavaScript-Misc +3 More Similar Reads What purpose does a <script> tag serve inside of a <noscript> tag? Usage of NoScript tag: The tag defines alternate content that will be displayed if the user has disabled script or browser does not support script.It can be used inside both <head> and <body> tag. Syntax:<noscript> Contents... </noscript> Example:HTML <html> <head 1 min read JavaScript Course Understanding Code Structure in JavaScript Inserting JavaScript into a webpage is much like inserting any other HTML content. The tags used to add JavaScript in HTML are <script> and </script>. The code surrounded by the <script> and </script> tags is called a script blog. The 'type' attribute was the most important a 3 min read Where should we use script tag in the HTML ? In this article, we are going to learn about that what are the reasons that we should not add the <script> tag at the top of the body tag inside the HTML code instead of we should add the script file at the end of the HTML code.Script Tag: It is used to add JavaScript inside the HTML code and 4 min read What's the difference between JavaScript and JScript? JavaScript: JavaScript is a programming language which is commonly used in wed development. Its code is only run in web browser. JavaScript is one of the core technologies of world wide web along with HTML and CSS. JavaScript was designed by Brendan Eich and it was first appeared in 4 December 1995. 2 min read Why do we need to specify the value with HTML elements ? In this article, we will see about the need to specify the value with HTML elements along with knowing the supported elements & their implementation through the examples.The value with the HTML element defines the default value for that element & those element's values will be displayed in t 1 min read When CDATA section is necessary within a script tag ? A CDATA section within a script tag is used to include data within a script element that should not be parsed as JavaScript. CDATA stands for Character Data, and it allows you to include characters that might otherwise be interpreted as HTML or XML markup. Without a CDATA section, the browser might 3 min read Like