HTML JavaScript

HTML JavaScript



There is a small part of the script program in HTMl that always adds interactivity to your website. In HTML you can generate a pop-up alert box message using a script, or you can provide a dropdown menu.

You can write various small tasks with the help of these scripts, and then you can easily trigger those tasks using HTML attributes.

Nowadays, only the JavaScript related framework is being used by most web developers, this is very good in web programming.

You can also put JavaScript code in a separate file, and after that you can include it anywhere.
We understand this with the help of some examples.


HTML JavaScript

Html external javascript

In HTML, if you want to define the functionality, and you want to use it in different HTML documents, it would be better to put that functionality into a separate JavaScript file and then it would be better to include that file in your HTML documents.

HTML internal script

You can write any of your script codes directly into the HTML document. We know that by using the <script> tag, you place the script code in the header in the document, and you can place your source code somewhere in the document but you remember that it is inside the <script> tag.


Html <script> tag
The <script> tag is used to define client-side scripts / javascript / in HTML.
If we understand this element, then the scripting statement contains either the scripting statement.
To select an HTML element in HTML, JavaScript generally uses the document getElementById () method.
Example-


<!DOCTYPE html>
<html>
<body>
<h2>Use JavaScript</h2>
<p>writes "Hello JavaScript!"</p>
<p id="Exm"></p>
<script>
document.getElementById("Exm").innerHTML = "Hello JavaScript!";
</script>
</body>
</html>

Result-
Use JavaScript
writes "Hello JavaScript!"


Javascript taste
For what JavaScript JavaScript can do in Hitam, we have given you some examples of this:

This example displays an event handler. This is a simple function event handler, in which when a user brings the mouse to the paragraph, we call this function.
Example-


<!DOCTYPE html>
<html>
   <head>
      <title>Event Handlers Example</title>
      <base href = "https://www.webstudy.ooo/" >
      <script type = "text/JavaScript">
         function EventHandler() {
            alert("I'm event handler!!");
         }
      </script>
   </head>
   <body>
      <p onmouseover = "EventHandler();">Bring your mouse here ......</p>
   </body>
</html>

Result

Bring your mouse here ......



for example can change HTML content with the help of javascript
Example-


<!DOCTYPE html>
<html>
<body>
<h1>My JavaScript</h1>
<p>change HTML content with the help of javascript:</p>
<button type="button" onclick="myFunction()">Click Me!</button>
<p id="Exp">This is a webstudy site.</p>
<script>
function myFunction() {
    document.getElementById("Exp").innerHTML = "Hello webstudy site!";
}
</script>
</body>
</html>

Result-
My JavaScript
change HTML content with the help of javascript:

This is a webstudy site.


For example, we can change the HTML styles with the help of javascript
Example-


<!DOCTYPE html>
<html>
<body>
<h1>My JavaScript</h1>
<p id="Exp">we can change the HTML styles with the help of javascript</p>
<script>
function myFunction() {
    document.getElementById("Exp").style.fontSize = "25px";
    document.getElementById("Exp").style.color = "red";
    document.getElementById("Exp").style.backgroundColor = "yellow";     
}
</script>
<button type="button" onclick="myFunction()">Click Me!</button>
</body>
</html>

Result-
My JavaScript

we can change the HTML styles with the help of javascript



HTML <Noscript> Elements
In the HTML java script, you can also provide alternative information to users who do not support browser scripts, and for users who have disabled the script option in their browser. You can do this for them by using <noscript> tags.
Example-


<!DOCTYPE html>
<html>
<body>
<p id="Exp"></p>
<script>
document.getElementById("Exp").innerHTML = "Hello JavaScript!";
</script>
<noscript>browser does not support JavaScript!</noscript>
<p>A browser does not support JavaScript - show the text written in the noscript element.</p>
</body>
</html>


HTML JavaScript-There is a small part of the script program in HTMl that always adds interactivity to your website. In HTML you can generate a pop-up alert box message using a script, or you can provide a dropdown menu.You can write various small tasks with the help of these scripts, and then you can easily trigger those tasks using HTML attributes.

Post a Comment

[blogger]

MKRdezign

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget