In this article, you will learn how inline JavaScript works with HTML. Inline JavaScript represents a block of code written between <script> tags in an html file. The advantage of using inline JavaScript in HTML files is that it reduces round trips from the web browser to the server. </script>
Let’s learn how to add basic statements in html files using inline JavaScript -
<!DOCTYPE html > <html> <head> <h2> This is a simple HTML file</h2> <script> document.write("Hi, This is an inline Javascript code written in between script tags"); </script> </head> </html>
Step 1 - In a simple html file, add the title tag
Step 2 - Add the script tag <script> below the title tag. </p></li> <li><p><b>Step 3</b> -In the script tag, use the document.write() function to print the text. </p></li> </ul> <h2>Example 2</h2> <p>In this example, let us use inline JavaScript to print an array from an html file. </p> <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class='brush:javascript;toolbar:false;'><!DOCTYPE html > <html> <head> <h2> This is a simple HTML file</h2> <script> document.write("An Inline Javascript code to display an array") document.write("<br>") const inputArray = [3,4,5,6,7,8] document.write("The array is defined as :", inputArray) </script> </head> </html></pre><div class="contentsignin">Copy after login</div></div> <h2>illustrate</h2> <ul class="list"> <li> <p><b>Step 1</b> - In a simple html file, add the title tag </p> <h2> and display the title of your choice. </h2> </li> <li><p><b>Step 2</b> - Add the script tag <script> below the title tag. </script>
Step 3 - In the script tag, define an array, inputArray, and add values to the array.
Step 4 - Print the array using document.write() function.
The above is the detailed content of How does inline JavaScript work with HTML?. For more information, please follow other related articles on the PHP Chinese website!