Way of Adding JS Code
Way of Adding JS Code
• 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
<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
<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>
</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>