Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the proper way to format a JavaScript tag?

Having developed web apps since 1996 I often find new ways of doing old things. So I was wondering what is the proper JavaScript tag to use on new development?

Currently I use something like this for XHTML

<script type="text/javascript">
/* <![CDATA[ */

/* ]]> */
</script> 

I have read somewhere that this may cause problem with older browsers.

But use to use the following:

<script language="javascript">

<script type="text/javascript">

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

What is the prefered method and why?

like image 467
Todd Moses Avatar asked Feb 21 '10 19:02

Todd Moses


People also ask

Where is the correct place to insert a JavaScript tag?

JavaScript in body or head: Scripts can be placed inside the body or the head section of an HTML page or inside both head and body. JavaScript in head: A JavaScript function is placed inside the head section of an HTML page and the function is invoked when a button is clicked.

What is the JavaScript format?

JS (JavaScript) are files that contain JavaScript code for execution on web pages. JavaScript files are stored with the . js extension.

How do you write JavaScript in HTML?

You can add JavaScript code in an HTML document by employing the dedicated HTML tag <script> that wraps around JavaScript code. The <script> tag can be placed in the <head> section of your HTML or in the <body> section, depending on when you want the JavaScript to load.

How do you write a script tag?

Definition and Usage. The <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.


1 Answers

Checkout what Crockford has to say. In summary:

<script src="url"></script>
like image 171
rkj Avatar answered Oct 05 '22 10:10

rkj