Skill Making

Always Increase Your Knowledge

Best Ways to write JavaScript Code for HTML file

Best Ways to write JavaScript Code for HTML file

 

You should also read these articles

Table Tag

Introduction of JavaScript

Today in this article I will tell you something about JavaScript basics. If you have any problem to write JavaScript code or if you are a beginner in JavaScript then you are at right place. Here you can get the right answer for your query. Here you can get the best ways to write JavaScript Code for HTML file. I hope you will get your answer. These are some points may help you to write JavaScript Code




  • You can write JavaScript code in the same HTML file.
  • You can write JavaScript code into the same HTML file like this:
<script type=”text/javascript”>

                -------------------------

                -------------------------

</script>
  • You can also write JavaScript code in a separate file, which can be embedded into your HTML file. You don’t need to write <script> tag in your separate file which has .js extension.
  • You can embed your external .js file with your HTML file by follow this:
<script type=”text/javascript” src=”externalfile.js”>

</script>




Write JavaScript Code into HTML file

  • JavaScript code must be inserted between <script> and </script> tags.
  • You can place JavaScript code at anywhere in HTML document (body or head).
  • You should start your JavaScript code like this
<script type=”text/javascript”></script>
  • The type attribute is not always required. JavaScript is the default scripting language in HTML.

Best Ways to write JavaScript Code

  • You can write JavaScript code into <head> tag.
  • You can write JavaScript code into <body> tag.
  • You can write JavaScript code into an external file.




  1. Write JavaScript Code into the head tag

If you want to write JavaScript code into <head> tag then you should follow this type to write your JavaScript code.

<html>

<head>

<script type=”text/javascript”>

document.write(“welcome”);

</script>

<body>

<h1>Welcome SKILLMAKING </h1>

</body>

</html>

Output:

write javascript code

  1. Write JavaScript Code into body tag

If you want to write JavaScript code into <body> tag then you should read this code which is given below. Here you can take an idea to write JavaScript code into body tag.




<html>

<head>

<title>SKILLMAKING</title>

</head>

<body>

<h1>Welcome SKILLMAKING </h1>

<script type=”text/javascript>

document.write(“welcome”);

</script>

</body>

</html>

write javascript code

  1. Write JavaScript code into external file

If you want to write JavaScript code into an external file then you should read this code which is given below.

<html>

<head>

<title>SKILLMAKING</title>

<script type=”text/javascript” src=”file.js”>

</script>

</head>

<body>

<h1>WELCOME </h1>

</body>

</html>

File.js file

document.write(“hello JavaScript”);

Output

write javascript code




Conclusion

So here you get the best ways to write JavaScript code for your HTML file. I hope you will get the right answer for your query. Thank you for reading this article till the end. If you have any question regarding this article then you should write them into the comment section below. If you love this article then show your love into the comment section below.

Leave a Reply

Your email address will not be published. Required fields are marked *

Skill Making © 2018 Frontier Theme