To define a client-side script in HTML5, we can do <script> tag or adding external script file by src attribute to the HTML file. <script> tag contains the JavaScript to be added for the client-side scripting.
Syntax:
<script>
// JavaScript goes here
console.log('GeeksforGeeks');
</script>
Below are the examples for the above approach:
Example 1: Here script is added using <script> tag.
HTML
<!DOCTYPE html>
< html >
< body >
< h1 >Welcome To GFG</ h1 >
< p id = "id1" >
Default code has been loaded into the Editor.
</ p >
< script >
document.getElementById("id1").innerHTML=
"Welcome to GeeksForGeeks"
</ script >
</ body >
</ html >
|
Output:

Example 2: Here, external JavaScript is used for scripting.
index.html
<!DOCTYPE html>
< html >
< body >
< h2 >External JavaScript</ h2 >
< p id = "id1" >
This is before you click the button
</ p >
< button type = "button" onclick = "clickMe()" >
Click Me
</ button >
< script src = "main.js" ></ script >
</ body >
</ html >
|
main.js
function clickMe() {
document.getElementById( "id1" ).innerHTML =
"This is after you click the button" ;
}
|
Output:


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
22 Mar, 2021
Like Article
Save Article