info To participate please Register or Login.

How to add JavaScript to your website

By Simon on February 21st, 2007. Published in JavaScript.

Adding JavaScript to your site is very easy. You can do it using four different methods.

Add this script tag in your web document:

‹script type="text/javascript"›
// Your code here
‹/script›

If you want to support older brosers or if you use transitional XHTML, the more stricter version of HTML you should use this code:

‹script type="text/javascript"›
‹!--
// Your code here
-->
‹/script›

In Strict XHTML you will need to use the CDATA commenting syntax to comment out your code:

‹script type="text/javascript"›
// ‹ ![CDATA[
// Your code here
// ]]›
‹/script›

The best way to add JavaScript to your site when using XHTML is to add the JavaScript in it’s own document (.js) and link it in using this line of code placed in your header:

‹code›‹script type="text/javascript" xsrc="the link to the JavaScript file.js"›‹/script›‹/code›

2 Responses

Express yourself. Tell us your opinion. Make a comment!

  • Thank you for the tutorial,

    but could you please add some links to where I could ascertain some Javascript? Premade please, thanks :)

  • Write your comment

    Warning Spam and inflammatory comments will be deleted. If this is the first time you make a comment on Easy Webbers it will be held for moderation before being published.