JAVASCRIPT TUTORIALS

1. JavaScript is the world's most popular programming language.

2. JavaScript is the programming language of the Web.

3. JavaScript is easy to learn.

4. This tutorial will teach you JavaScript from basic to advanced.


Why Study JavaScript?

JavaScript is one of the 3 languages all web developers must learn:

1. HTML to define the content of web pages.

2. CSS to specify the layout of web pages.

3. JavaScript to program the behavior of web pages.

This tutorial covers every version of JavaScript:

* The Original JavaScript ES1 ES2 ES3 (1997-1999)
* The First Main Revision ES5 (2009)
* The Second Revision ES6 (2015)
* The Yearly Additions (2016, 2017, 2018)

JavaScript Introduction

First of all, how to use JavaScript in a HTML document

There are several ways to use JS in a HTML document. We can write a JavaScript Code inside the <body> tag using <script> tag.

HTML

              
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document </title>
</head>
<body>
<h2>This is my HTML Code</h2>

<script>This is my JavaScript Code</script>

</body>
</html>
            
          
Code Copied

Or, you can use separate(External) JavaScript code file by attaching it in HTML file.
Like this: (Lets say JavaScript code file name is javaScript.js)

HTML

              
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document </title>
</head>
<body>
<h2>This is my HTML Code</h2>

<script src="javaScript.js"></script>

</body>
</html>
            
          
Code Copied

Now lets see some examples of what JavaScript can do.

JavaScript Can Change HTML Content

One of many JavaScript HTML methods is getElementById().

The example below "finds" an HTML element (with id="demo"), and changes the element content (innerHTML) to "Hello JavaScript":

HTML

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

JavaScript accepts both double and single quotes:

HTML

                      
document.getElementById('demo').innerHTML = 'Hello JavaScript';  
                    
                  
Code Copied

JavaScript Can Change HTML Attribute Values

In this example JavaScript changes the value of the src (source) attribute of an <img> tag:.

HTML

                          
button=addEventlistener("click",function(){document.getElementById('myImage').src='pic_bulbon.gif'})
                        
                      
Code Copied

JavaScript Can Change HTML Styles (CSS)

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

HTML

                              
document.getElementById("demo").style.fontSize = "35px"; 
                            
                          
Code Copied

IF YOU WANT TO LEARN MORE PLEASE VISIT W3SCHOOL OR JUST CLICK HERE.