4/4/13
HTML Scripts
HTML Scripts
Previous
JavaScripts make HTML pages more dynamic and interactive.
Next Chapter
Try it Yourself - Examples
Insert a script How to insert a script into an HTML document. Use of the <noscript> tag How to handle browsers that do not support scripting, or have scripting disabled.
The HTML <script> Tag
The <script> tag is used to define a client-side script, such as a JavaScript. The <script> element either contains scripting statements or it points to an external script file through the src attribute. The required type attribute specifies the MIME type of the script. Common uses for JavaScript are image manipulation, form validation, and dynamic changes of content. The script below writes Hello World! to the HTML output:
Example
< s c r i p t > d o c u m e n t . w r i t e ( " H e l l oW o r l d ! " ) < / s c r i p t >
Try it yourself
Tip: To learn more about JavaScript, visit our JavaScript tutorial!
The HTML <noscript> Tag
The <noscript> tag is used to provide an alternate content for users that have disabled scripts in their browser or have a browser that doesnt support client-side scripting. The <noscript> element can contain all the elements that you can find inside the <body> element of a normal HTML page. The content inside the <noscript> element will only be displayed if scripts are not supported, or are disabled in the users browser:
Example
< s c r i p t > d o c u m e n t . w r i t e ( " H e l l oW o r l d ! " ) < / s c r i p t > < n o s c r i p t > S o r r y ,y o u rb r o w s e rd o e sn o ts u p p o r tJ a v a S c r i p t ! < / n o s c r i p t >
w3schools.com/html/html_scripts.asp 1/2
4/4/13
HTML Scripts
Try it yourself
A Taste of JavaScript (From Our JavaScript Tutorial)
Here are some examples of what JavaScript can do:
JavaScript can write directly into the HTML output stream:
d o c u m e n t . w r i t e ( " < p > T h i si sap a r a g r a p h < / p > " ) ;
Try it yourself
JavaScript can react to events:
< b u t t o nt y p e = " b u t t o n "o n c l i c k = " m y F u n c t i o n ( ) " > C l i c kM e ! < / b u t t o n >
Try it yourself
JavaScript can manipulate HTML styles:
d o c u m e n t . g e t E l e m e n t B y I d ( " d e m o " ) . s t y l e . c o l o r = " # f f 0 0 0 0 " ;
Try it yourself
HTML Script Tags
Tag <script> <noscript> Description Defines a client-side script Defines an alternate content for users that do not support client-side scripts
Previous
Next Chapter
w3schools.com/html/html_scripts.asp
2/2