Related Topics
Introduction
Html page 1
Html page 2
Html page3
Html page4
HTML Elements and structure
Html page 5
Html page 6
Html page 7
HTML Headings and Paragraphs
Html page 8
Html page 9
Html page 10
HTML Lists and Tables
Html page 11
Html page 12
Html page 13
HTML Forms and Input Fields
Html page 14
Html page 15
Html page 16
HTML Images and Media
Html page 17
Html page 18
HTML Links and Anchors
Html page 19
Html page 20
Html page 21
HTML Styles and Formatting
Html page 22
HTML Semantic Elements
Html page 23
Html page 24
HTML Attributes
Html page 25
Html page 26
HTML JavaScript Integration
Html page 27
Html page 28
Html page 29
Html page 30
HTML Document and Browser Support
Html page 31
Html page 32
HTML5 New Elements and Attributes
Html page 33
Html page 34
Html page 35
Html page 36
HTML Accessibility and Web Standards
Html page 37
Html page 38
Html page 39
HTML Responsive Design and Mobile Devices.
Html page 40
Html page 41
Html page 42
Introduction
Data Structure Page 1
Data Structure Page 2
Data Structure Page 3
Data Structure Page 4
Data Structure Page 5
Data Structure Page 6
Data Structure Page 7
Data Structure Page 8
String
Data Structure Page 9
Data Structure Page 10
Data Structure Page 11
Data Structure Page 12
Data Structure Page 13
Array
Data Structure Page 14
Data Structure Page 15
Data Structure Page 16
Data Structure Page 17
Data Structure Page 18
Linked List
Data Structure Page 19
Data Structure Page 20
Stack
Data Structure Page 21
Data Structure Page 22
Queue
Data Structure Page 23
Data Structure Page 24
Tree
Data Structure Page 25
Data Structure Page 26
Binary Tree
Data Structure Page 27
Data Structure Page 28
Heap
Data Structure Page 29
Data Structure Page 30
Graph
Data Structure Page 31
Data Structure Page 32
Searching Sorting
Data Structure Page 33
Hashing Collision
Data Structure Page 35
Data Structure Page 36

JAVASCRIPT
<title>Dynamic Web Page</title>
<h1 id="greeting">Hello, World!</h1>
<button>Change Greeting</button>
JavaScript (script.js):
function changeGreeting() {
var greetingElement = document.getElementById("greeting");
greetingElement.textContent = "Welcome to the Dynamic Web Page!";
}
In this example, we have an HTML page with a heading element (<h1>
) displaying the greeting “Hello, World!” and a button element. When the button is clicked, the JavaScript function changeGreeting()
is executed.
The JavaScript code retrieves the element with the id “greeting” using document.getElementById()
. It then updates the text content of the element using the textContent
property. In this case, the greeting is changed to “Welcome to the Dynamic Web Page!”.
When the button is clicked, the JavaScript code dynamically modifies the HTML element, and the updated text is immediately reflected on the web page without the need for a page refresh.
This is just a simple example, but JavaScript can be used to perform more complex updates, such as manipulating multiple elements, changing styles, making AJAX requests to fetch and display data from a server, and much more.
<title>JavaScript in HTML</title>
// Inline JavaScript code
function greet() {
console.log('Hello, world!');
}
greet();
<!-- HTML content -->
External JavaScript File: You can also include an external JavaScript file by linking it in the HTML file using the
<script>
tag’ssrc
attribute. Create a separate.js
file and specify its path using thesrc
attribute. For example:
<title>JavaScript in HTML</title>
<!-- HTML content -->
JavaScript (script.js):
// External JavaScript code
function greet() {
console.log('Hello, world!');
}
greet();
Make sure the src
attribute value points to the correct location of the JavaScript file.
Asynchronous Loading: If you want to load JavaScript asynchronously to improve page loading performance, you can use the
async
ordefer
attribute with the<script>
tag.
<script async src="script.js"></script>
: The script is fetched asynchronously while the HTML parsing continues. Once the script is fetched, it is executed immediately. This can be useful for scripts that don’t depend on the DOM.<script defer src="script.js"></script>
: The script is fetched asynchronously but is executed only after the HTML parsing is complete. This is useful when the script depends on the DOM or requires a specific order of execution.
Remember to place the <script>
tag appropriately in the HTML document, depending on when you want the JavaScript code to be executed.
By using these methods, you can effectively include JavaScript code in an HTML file and make it executable within a web page.




Popular Category
Topics for You
Introduction
Html page 1
Html page 2
Html page3
Html page4
HTML Elements and structure
Html page 5
Html page 6
Html page 7
HTML Headings and Paragraphs
Html page 8
Html page 9
Html page 10
HTML Lists and Tables
Html page 11
Html page 12
Html page 13
HTML Forms and Input Fields
Html page 14
Html page 15
Html page 16
HTML Images and Media
Html page 17
Html page 18
HTML Links and Anchors
Html page 19
Html page 20
Html page 21
HTML Styles and Formatting
Html page 22
HTML Semantic Elements
Html page 23
Html page 24
HTML Attributes
Html page 25
Html page 26
HTML JavaScript Integration
Html page 27
Html page 28
Html page 29
Html page 30
HTML Document and Browser Support
Html page 31
Html page 32
HTML5 New Elements and Attributes
Html page 33
Html page 34
Html page 35
Html page 36
HTML Accessibility and Web Standards
Html page 37
Html page 38
Html page 39
HTML Responsive Design and Mobile Devices.
Html page 40
Html page 41
Html page 42
Introduction
Data Structure Page 1
Data Structure Page 2
Data Structure Page 3
Data Structure Page 4
Data Structure Page 5
Data Structure Page 6
Data Structure Page 7
Data Structure Page 8
String
Data Structure Page 9
Data Structure Page 10
Data Structure Page 11
Data Structure Page 12
Data Structure Page 13
Array
Data Structure Page 14
Data Structure Page 15
Data Structure Page 16
Data Structure Page 17
Data Structure Page 18
Linked List
Data Structure Page 19
Data Structure Page 20
Stack
Data Structure Page 21
Data Structure Page 22
Queue
Data Structure Page 23
Data Structure Page 24
Tree
Data Structure Page 25
Data Structure Page 26
Binary Tree
Data Structure Page 27
Data Structure Page 28
Heap
Data Structure Page 29
Data Structure Page 30
Graph
Data Structure Page 31
Data Structure Page 32
Searching Sorting
Data Structure Page 33
Hashing Collision
Data Structure Page 35
Data Structure Page 36
Go through our study material. Your Job is awaiting.