HOME C C++ PYTHON JAVA HTML CSS JAVASCRIPT BOOTSTRAP JQUERY REACT PHP SQL AJAX JSON DATA SCIENCE AI

HTML JavaScript

In the context of web development, "HTML" and "JavaScript" are two distinct but closely related technologies that are often used together to create dynamic and interactive web pages.

The HTML <script> Tag

The HTML <script> tag is used to define a client-side script (JavaScript).

The <script> element either contains script statements, or it points to an external script file through the src attribute.

Common uses for JavaScript are image manipulation, form validation, and dynamic changes of content.

To select an HTML element, JavaScript most often uses the document.getElementById() method.

This JavaScript example writes "Hello JavaScript!" into an HTML element with id="demo":

Example

<script>
document.getElementById("demo").innerHTML = "Hello JavaScript!";
</script>
You can click on above box to edit the code and run again.

Output

Use JavaScript to Change Text

This example writes "Hello JavaScript!" into an HTML element with id="demo":

A Taste of JavaScript

Here are some examples of what JavaScript can do:

Example


document.getElementById("demo").innerHTML = "Hello JavaScript!";
You can click on above box to edit the code and run again.

Output

Example


document.getElementById("demo").style.fontSize = "35px";
document.getElementById("demo").style.color = "red";
document.getElementById("demo").style.backgroundColor = "yellow";

You can click on above box to edit the code and run again.

Output

Example

document.getElementById("image").innerHTML = ""picture.gif"";

You can click on above box to edit the code and run again.

Output

The HTML <noscript> Tag

The <noscript> tag in HTML is used to provide alternative content that should be displayed when a browser does not support or has disabled JavaScript. The content within the <noscript>. tag is intended for situations where JavaScript is either not available or disabled in the user's browser.

Example

<p id="demo">

<script> document.getElementById("demo").innerHTML = "Hello JavaScript!"; </script> <noscript>Sorry, your browser does not support JavaScript!</noscript> <p>A browser without support for JavaScript will show the text written inside the noscript element.</p>
You can click on above box to edit the code and run again.

Output

A browser without support for JavaScript will show the text written inside the noscript element.