Hrushikesh Kokardekar
Posted on July 31, 2021
How many of you like dynamic web pages ? Using HTML and CSS you can create and style static web page but you cannot perform actions on it. To make your web page dynamic JavaScript language is used.
JavaScript was created by Brendan Eich. It is a high-level, East to learn language use to create dynamic web pages. JavaScript is used to perform actions on elements like creating alert box on click of button. Performing some actions according to some condition by using if-else etc.
There are many such applications of JavaScript.
In JavaScript we select the element on which action is to performed by providing the id or class to it.
Let's see how to embed your JavaScript in your HTML.
Like CSS we have multiple ways to embed our JavaScript in your HTML.
Method - 1 Using script tag
Like we used style tag in the same file to add styling to our pages here we use script tag. Inside script tag we write our script and add JS in our HTML. You can see the code below. Don't worry about the script that I write inside the script tag.
Code :
Output :
You can see that without writing a single word inside the p tag how I printed "Welcome to JavaScript" . That's the uniqueness of JavaScript.
Let's see the second method
Method - 2 Creating Separate JavaScript file
Again like CSS we create a separate JavaScript file with extension .js . Now the question is how to link it in our HTML. So here again script tag is used. the src attribute is used to provide location of your JavaScript file. You can see the code below .
Code :
Output :
That's the Second Method of adding your JavaScript inside your HTML.
So that's it for today. Don't worry about the script that I wrote inside the script tag or js file.
In next post we will explore some more topic in JS .
Meet you next post 😊😊
Happy Coding 👩💻👩💻👩💻
Posted on July 31, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.