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?
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.
JS (JavaScript) are files that contain JavaScript code for execution on web pages. JavaScript files are stored with the . js extension.
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.
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.
Checkout what Crockford has to say. In summary:
<script src="url"></script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With