DOM HTMLCollection

An HTMLCollection object is an array-like list of HTML elements. Methods like the getElementsByTagName() returns an HTMLCollection. Properties and Methods The following properties and methods can be used on a HTMLCollection object: Property / Method Description item() Returns the element at the specified index in an HTMLCollection length Returns the number of elements in an […]

HTML5 Web Workers

A web worker is a JavaScript running in the background, without affecting the performance of the page. What is a Web Worker? When executing scripts in an HTML page, the page becomes unresponsive until the script is finished. A web worker is a JavaScript that runs in the background, independently of other scripts, without affecting […]

HTML DOM Progress Object

Progress Object  The Progress Object is new in HTML5. The Progress object represents an HTML <progress> element. The <progress> element represents the progress of a task. Access a Progress Object You can access a <progress> element by using getElementById(): Example var x = document.getElementById(“myProgress”); Try it Yourself » Create a Progress Object You can create a […]

HTML DOM Pre Object

Pre Object The Pre object represents an HTML <pre> element. Access a Pre Object You can access a <pre> element by using getElementById(): Example var x = document.getElementById(“myPre”); Try it Yourself » Create a Pre Object You can create a <pre> element by using the document.createElement() method: Example var x = document.createElement(“PRE”); Try it Yourself » Pre […]

HTML DOM Mark Object

Mark Object  The Mark Object is new in HTML5. The Mark object represents an HTML <mark> element. Note: The <mark> element is not supported in Internet Explorer 8 and earlier versions. Access a Mark Object You can access a <mark> element by using getElementById(): Example var x = document.getElementById(“myMark”); Try it Yourself » Create a Mark Object […]

HTML srclang Attribute

Example A video with two subtitle tracks: <video width=”320″ height=”240″ controls> <source src=”forrest.mp4″ type=”video/mp4″>  <track src=”subtitles_en.vtt” kind=”subtitles” srclang=”en” label=”English”> <track src=”subtitles_no.vtt” kind=”subtitles” srclang=”no” label=”Norwegian”> </video> Definition and Usage The srclang attribute specifies the language of the track text data. This attribute is required if kind=”subtitles”. Tip: To view all available language codes, go to our Language code reference. Browser Support The numbers in the table specify the first browser version […]

HTML <u> Tag

Example Underline a misspelled word with the <u> tag: <p>This is a <u>parragraph</u>.</p> Try it Yourself » Definition and Usage The <u> tag represents some text that should be stylistically different from normal text, such as misspelled words or proper nouns in Chinese. Browser Support Element <u> Yes Yes Yes Yes Yes Tips and Notes Tip: Avoid […]

HTML DOM Code Object

The Code object represents an HTML <code> element. Access a Code Object You can access a <code> element by using getElementById(): Example var x = document.getElementById(“myCode”); Try it Yourself » Create a Code Object You can create a <code> element by using the document.createElement() method: Example var x = document.createElement(“CODE”); Try it Yourself » Standard Properties and […]

HTML Element Reference

HTML Tags Ordered Alphabetically = New in HTML5 Tag Description <!–…–> Defines a comment <!DOCTYPE> Defines the document type <a> Defines a hyperlink <abbr> Defines an abbreviation or an acronym <acronym> Not supported in HTML5. Use <abbr> instead. Defines an acronym <address> Defines contact information for the author/owner of a document <applet> Not supported in HTML5. Use <embed> or <object> instead. […]

JavaScript Best Practices

Avoid global variables,  avoid new,  avoid  ==,  avoid eval() Avoid Global Variables Minimize the use of global variables. This includes all data types, objects, and functions. Global variables and functions can be overwritten by other scripts. Use local variables instead, and learn how to use closures. Always Declare Local Variables All variables used in a function […]

JavaScript Random

Math.random() Math.random() returns a random number between 0 (inclusive),  and 1 (exclusive): Example Math.random();              // returns a random number Try it Yourself » Math.random() always returns a number lower than 1. JavaScript Random Integers Math.random() used with Math.floor() can be used to return random integers. Example Math.floor(Math.random() * 10);     // returns a random integer from 0 to […]

JavaScript Comments

JavaScript comments can be used to explain JavaScript code, and to make it more readable. JavaScript comments can also be used to prevent execution, when testing alternative code. Single Line Comments Single line comments start with //. Any text between // and the end of the line will be ignored by JavaScript (will not be […]

HTML Layouts

HTML Layout Elements Websites often display content in multiple columns (like a magazine or newspaper). HTML5 offers new semantic elements that define the different parts of a web page: <header> – Defines a header for a document or a section <nav> – Defines a container for navigation links <section> – Defines a section in a […]