0% found this document useful (0 votes)
61 views

Way of Adding JS Code

The document describes two methods for adding JavaScript to an HTML document: 1. Inline JavaScript - Adding <script> tags within the <head> or <body> sections and writing JavaScript code directly within. 2. External JavaScript - Creating .js files containing JavaScript code, linking them using <script> tags with an src attribute pointing to the .js file location, and including the <script> tags within the <head> or <body> sections. External files allow code reuse across pages.

Uploaded by

aarti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views

Way of Adding JS Code

The document describes two methods for adding JavaScript to an HTML document: 1. Inline JavaScript - Adding <script> tags within the <head> or <body> sections and writing JavaScript code directly within. 2. External JavaScript - Creating .js files containing JavaScript code, linking them using <script> tags with an src attribute pointing to the .js file location, and including the <script> tags within the <head> or <body> sections. External files allow code reuse across pages.

Uploaded by

aarti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Way of adding JavaScript

• Inline
– Inside head Tag
– Inside body Tag
<script>
• External file
</script>
– Inside head Tag
– Inside body Tag
Inline
• Inside head Tag

<html>
<head><title>Hello JS</title>
<script type="text/javascript">
document.write(“Hello Geekyshows”);
</script>
</head>
<body>
<h1>I am Heading</h1>
<p>I am first Paragraph.</p>
</body>
</html>
Inline
• Inside body Tag

<html>
<head><title>Hello JS</title></head>
<body>
<h1>I am Heading</h1>
<p>I am first Paragraph.</p>
<script type="text/javascript">
document.write(“Hello Geekyshows”);
</script>
</body>
</html>
External Notepad

• Inside head Tag document.write(“Hello Geekyshows”);

<html>
<head><title>Hello JS</title>
<script type="text/javascript">
src=“geek.js” type="text/javascript">
</script>
document.write(“Hello Geekyshows”);
</script>
• Save with .js extension
</head> Ex: - geek.js
<body> • Now link this file to HTML
<h1>I am Heading</h1>
<p>I am first Paragraph.</p>
</body>
</html>
External Notepad

• Inside body Tag document.write(“Hello Geekyshows”);

<html>
<head><title>Hello JS</title></head>
<body>
<h1>I am Heading</h1>
<p>I am first Paragraph.</p> • Save with .js extension
<script type="text/javascript">
src=“geek.js” type="text/javascript"> Ex: - geek.js
</script>
document.write(“Hello Geekyshows”); • Now link this file to HTML
</script>
</body>
</html>
<script type="text/javascript"> <script src = “geek.js” type="text/javascript">
document.write(“Hello World”);
</script>
</script>

• <script> - Opening Script Tag.


• src – It’s an attribute of script tag. It defines source/location of script file.
• geek.js – This is our script file. Where geek is file name and .js is the extension
of javascript file.
• type – It’s an attribute of script tag which tells the browser it is a javascript. This
is optional now a days.
• text/javascript – Its type of document
• document.write(“Hello World”); - This is a function to display data.
• </script> - Closing Script tag
<html>
<head><title>Hello JS</title></head>
<body>
<h1>I am Heading</h1>
<p>I am first Paragraph.</p>

<script src = “geek1.js” type="text/javascript"></script>


<script src = “geek2.js” type="text/javascript"></script>
<script src = “geek3.js” type="text/javascript"></script>

</body>
</html>
<html>
<head><title>Hello JS</title></head>
<body>
<h1>I am Heading</h1>
<p>I am first Paragraph.</p>

<script type="text/javascript">
<script src = “geek1.js” type="text/javascript">
document.write(“Hello world”);
document.write(“Hello world”);
</script>
</script>
<script src = “geek1.js” type="text/javascript"> </script>

</body>
</html>

You might also like