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

JavascriptWeb DevelopmentFront End Technology

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>

Example

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>
raja
Published on 23-Apr-2018 16:33:08
Advertisements