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

JavaScript Introduction


JavaScript is the most popular programming language in the world.

JavaScript is the language for the web, for HTML, for servers, PCs, laptops, tablets, cell phones, and more.


JavaScript is a Scripting Language

A scripting language is a lightweight programming language.

JavaScript code can be inserted into any HTML page, and it can be executed by all types of web browsers.

JavaScript is easy to learn.

Below is a taste of what JavaScript can do.


Change the Content of HTML Elements

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

It is very common to use JavaScript to manipulate the DOM (to change the content of HTML elements).

Example

x = document.getElementById("demo");  //Find the HTML element with id="demo"
x.innerHTML = "Hello JavaScript";     //Change the content of the HTML element

Try it yourself »

document.getElementById() is one of the most commonly used HTML DOM methods.

You can also use JavaScript to:

  • Delete HTML elements
  • Create new HTML elements
  • Copy HTML elements
  • And more ...

You will find several chapters, about the HTML DOM, in later chapters of this tutorial.


Change the Value of HTML Attributes

This example changes the source attribute (src) of an HTML <image> 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.


Change HTML Styles (CSS)

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

Example

x = document.getElementById("demo");  //Find the HTML element with id="demo"
x.style.fontSize = "25px";            //Change the font size
x.style.color = "#ff0000";            //Change the color

Try it yourself »


Validate Input

JavaScript is commonly used to validate input:

Please input a number

 


Try it yourself »


Did You Know?

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

ECMA-262 is the official name of the JavaScript standard.

JavaScript was invented by Brendan Eich. It appeared in Netscape (a no longer existing browser) in 1995, and has been adopted by ECMA (a standard association) since 1997.



Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE