Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to declare script tag in HTML5?

I have seen many different ways in declaring script tag. Some of them are:

Variation 1:

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

Variation 2:

<script type="text/javascript">
     //<![CDATA[
     // some javascript here
     //]]>
</script>

Variation 3:

 <script language="javascript">
     //some javascript here
 </script>

Variation 4:

       <script>
          //some javascript here
       </script>

There are also other variations as well. When we work in HTML5 + js then which way is more appropriate in declaring Script tag?

like image 658
kta Avatar asked Jan 06 '14 10:01

kta


People also ask

Which is the most appropriate place to insert a script in html5?

Scripts can be placed in the <body> , or in the <head> section of an HTML page, or in both.

How do you define a script tag in HTML?

Definition and UsageThe <script> tag is used to embed a client-side script (JavaScript). The <script> element either contains scripting statements, or it points to an external script file through the src attribute. Common uses for JavaScript are image manipulation, form validation, and dynamic changes of content.

What html5 tag is used for including a script?

<script>: The Script element. The <script> HTML element is used to embed executable code or data; this is typically used to embed or refer to JavaScript code.

Where is the best place to put a script tag?

The script tag should always be used before the body close or at the bottom in HTML file. The Page will load with HTML and CSS and later JavaScript will load.


1 Answers

In HTML5 you don't need an additional attribute like "type". Just declare JavaScript code with <script></script>.

like image 185
Praind Avatar answered Sep 17 '22 18:09

Praind