0
Java script

Basic Javascript Tutorial

By March 12, 2021December 4th, 2021No Comments

Welcome to JavaScript Tutorial. If you are looking for a free and simple JavaScript tutorial, you are in the right place. To learn JavaScript, you need to be familiar with HTML and CSS, but if you do not know, do not worry at all, because their free tutorials are available on the PinkPen site. By clicking on HTML, you will enter the HTML school also by clicking on CSS, you will have access to all CSS training.

Introduction to JavaScript

At first glance, you might think that its name is similar to Java and similar to that language. But in fact, they are completely different, and perhaps the reason for this resemblance to advertising because at that time Java was very prevalent. It is one of the most popular and widely used web-based programming languages in the world. JavaScript to program the behavior of web pages. You do not need to buy or download it because it is in your mobile or laptop browser or all your smart gadgets. Java Script Can Change HTML Content and HTML Attribute Values and  HTML Styles (CSS). also  Can Show and hide HTML Elements.

How and where to use JavaScript

First, let us explain where and how we use it. There are many ways to use that we will teach you the most widely used and best methods.

Add external JS codes

The first method we look at is that you write your JS code in a separate file and then you can call in any number of HTML pages you want. For example, in a separate file, we write a program that changes the text of the paragraph. The JavaScript code of the site is as follows.

function myFunction() {
  document.getElementById("example").innerHTML = "Congratulations, the paragraph has changed.";
}

And then we call it in the main program file.

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

The external method is used when many HTML pages use the same JavaScript code. This file should be saved with the .js extension and you can use it in head and body and it does not matter. In general, we put only simple code inside HTML and the rest of the code in a separate file. The good thing about this method is that the browser stores the js file in its memory and the speed of the site should be increased.

Use js code inside HTML

You can also use JavaScript code in html using the script tag. You need to put your code between the scripts tags, the example below will help you to get more familiar with this method.

<script>
document.getElementById("example").innerHTML = "hellow world";
</script>

also, You can use the script tag as many times as you want and wherever you want in the program. It does not matter if you are using it in the head or in the body.

<html>
<body>
  <p>JavaScript Tutorial</p>

 <script>
    alert( 'pinkpen.net' );
  </script>
</body>
</html>
moji

moji

I am a computer engineering student, I have been working in SEO and WordPress for almost 8 years and I also have programming skills.

Leave a Reply

asdas

Copyright © 2019 pinkpen.net