Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Do you need text/javascript specified in your <script> tags?

Is the usage of text/javascript still supported in a <script> tag? When JavaScript launched, the type attribute was used in the <script> tag. Is it still essential?



1 Answer
Sai Subramanyam

In an HTML page, mostly text/javascript is used in the <script> tag.

Here’s an example

<script type="text/javascript">
</script>

However, the introduction of HTML5 brought some new improvements. JavaScript became the default language for HTML5 and modern browsers. Therefore, now adding text/javascript isn’t required in <script> tag.

<script>
</script>

Let’s see an example in jQuery.

Live Demo

<html>
   <head>
      <title> jQuery Example</title>
      <script src = “https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
      <script>
         $(document).ready(function(){
            document.write("Hello, World!");
         });
      </script>
   </head>
   <body>
      <h1>Hello</h1>
   </body>
</html>

Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.