Inline and External JavaScript

 Inline and External JavaScript

In this article we are goanna to see about Inline and External of JavaScript which is most important when you are going to start your career in JavaScript. Please read and enjoy this article if you want to give any feedback about your experience, we welcome.




There are two ways to include JavaScript code. One way is to include the code internally, known as the inline method. Using this method, the code is written inside the <script> element.

In the external method, the JavaScript code is contained in an entirely separate external document, with a file extension of .js. This extension, as you probably have already guessed, stands for JavaScript. The external file will then be referenced in the HTML document using the following syntax: 
<script src = "externalFile.js"></script>



An important point to remember about this syntax is that if there is any inline JavaScript code included between the <script> and </script> HTML tags, it will not execute because the browser has been told to look for JavaScript code outside the HTML document.

Internal JavaScript:

Inside head Tag
Inside body Tag

             <script>   </script>

External JavaScript:

Inside head Tag
Inside body Tag

             <script>   </script>

Internal JavaScript:

Inside head Tag

<html>
<head>
<title>JavaScript Tutorial</title>
<script type=“text/javascript”>
document.write(“Hello world”);
</script>
</head>
<body>
<h1>Inline JavaScript</h1>
</body>
</html>

Inside body Tag

<html>
<head>
<title>JavaScript Tutorial</title>
</head>
<body>
<h1>Inline JavaScript</h1>
<script type=“text/javascript”>
document.write(“Hello world”);
</script>
</body>
</html>


External JavaScript:



Inside head Tag

<html>
<head>
<title>JavaScript Tutorial</title>
<script src=“ons.js” type=“text/javascript”>
</script>
</head>
<body>
<h1>External JavaScript</h1>
</body>
</html>

Inside body Tag

<html>
<head>
<title>JavaScript Tutorial</title>
</head>
<body>
<h1>External JavaScript</h1>
<script src=“ons.js” type=“text/javascript”>
</script>
</body>
</html>





Share:

0 comments

Please leave your comments...... Thanks