HTML JavaScript

HTML and JavaScript are two core technologies used for building interactive web pages and web applications. HTML (Hypertext Markup Language) is used for structuring and presenting the content, while JavaScript is a programming language that allows you to add dynamic behavior and interactivity to your web pages.

Here's an example of how you can use JavaScript within an HTML document:

html
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Example</title>
<script>
// JavaScript code goes here
function greet() {
    var name = prompt('Please enter your name:');
    if (name) {
        var message = 'Hello, ' + name + '!';
        alert(message);
    }
}
</script>
</head>
<body>
    <h1>Welcome to my website</h1>

    <button onclick="greet()">Click me</button>

    <p>Some other content on the page.</p>
</body>
</html>

In this example, we have an HTML document that includes a JavaScript code block within the `<script>` tags. Inside the `<script>` tags, there is a JavaScript function called `greet()`. This function prompts the user to enter their name and displays a greeting message using an alert dialog.

The HTML portion of the code contains a `<button>` element with an `onclick` attribute. The `onclick` attribute specifies that the `greet()` function should be called when the button is clicked.

When you load this HTML document in a web browser and click the "Click me" button, the `greet()` function is executed, prompting you to enter your name. After entering your name, you will see an alert dialog displaying the greeting message.

This is just a simple example to demonstrate how JavaScript can be used within an HTML document. JavaScript has a wide range of capabilities, such as manipulating the HTML content, handling events, making HTTP requests, and much more. By combining HTML and JavaScript, you can create powerful and interactive web experiences.



About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc





 PreviousNext