<script> Element

To use JavaScript in a web page, the <script> element tags are used.


Strictly speaking, the TYPE attribute should be set to 'application/javascript', but since that doesn't work in IE it is more common to either find 'text/javascript' or nothing.


You may also sometimes find // <![CDATA[ just after the opening <script> tag and its associated // ]]> just before the closing </script > tag. These commented out lines inform XHTML supporting browsers that the content of the script is character data and should not be interpreted as XHTML markup, and are generally not bothered with but is good to know just in case.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">  
<html xmlns="https://www.w3.org/1999/xhtml" lang="en">  
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

		<script type="text/javascript">
		// <![CDATA[
			document.write("Javascript goes here!");
		// ]]>


Save & refresh browser:

Javascript goes here!

Leave a Reply