X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR BOOTSTRAP XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

JavaScript Introduction


JavaScript is the most popular programming language in the world.

It is the language for HTML, for the Web, for computers, servers, laptops, tablets, smart phones, and more.

This page contains some examples of what JavaScript can do in HTML.


JavaScript Can Change HTML Elements

The HTML DOM (the Document Object Model) is the official W3C standard for accessing HTML elements.

JavaScript can manipulate the DOM (change HTML contents).

The following example changes the content (innerHTML) of an HTML element identified with id="demo": 

Example

document.getElementById("demo").innerHTML = "Hello JavaScript";

Try it Yourself »

The method document.getElementById() is one of many methods in the HTML DOM.

You can use JavaScript to:

  • Change HTML elements
  • Delete HTML elements
  • Create new HTML elements
  • Copy and clone HTML elements
  • And much more ...

There are several chapters, about the HTML DOM, later in this tutorial.


JavaScript Can Change HTML Attributes

This example changes the value of the source attribute (src) of an HTML <img> element:

The Light bulb

Click the light bulb to turn on/off the light


Try it Yourself »

With JavaScript, you can change almost any HTML attribute.


JavaScript Can Change HTML Styles (CSS)

Changing the style of an HTML element, is a variant of changing an HTML attribute.

Example

document.getElementById("demo").style.fontSize = "25px";

Try it Yourself »

With JavaScript, you can change almost any CSS values.


JavaScript Can Validate Data

JavaScript is often used to validate input:

Please input a number between 1 and 10


Try it Yourself »


Did You Know?

Note JavaScript and Java are two completely different languages, both in concept and design.

JavaScript was invented by Brendan Eich, to be used in Netscape (a no longer existing browser) in 1995,
and was adopted by the ECMA standard association in 1997.

ECMA-262 is the official name. ECMAScript 5 (version 1.8.5 - July 2010) is the latest standard.



Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook