Hello friends, in today’s post, we are starting you about JavaScript (how to use where to in javascript) , what happens. How does the key work, so today you should tell about JavaScript.
What is <script> tag and how does it work?
JavaScript code or JavaScript links defined between <script> tags
Understand JavaScript code with an example
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <h2>full stack gyan JavaScript/h2> <p id="demo"></p> <script> document.getElementById("demo").innerHTML = "My First JavaScript"; </script> </body> </html>
If we talk about old JavaScript, then text/javascript is used in the type attribute, but now there is no need to define the type attribute in JavaScript.
Javascript function and its events
If we talk about the function of JavaScript, then the function of JavaScript blocks the code of JavaScript, that is, that function will not run until the JavaScript function is called.
We understand this through an example
A function will be called when any event is performed on that function like click on button, load etc.
Javascript’s <head> tag and <body> tag
You can add any number of scripts to an html document.
You can place the script in the <body> tag or the <head> tag of the html page, or both.
How to put JavaScript in <head> tag?
In this example given to you, the function of JavaScript has been placed in the section of <head> tag in the page of html
This function is called a button click event so that the declared function is called when that button is clicked.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <script> function myFunction() { document.getElementById("demo").innerHTML = "Click to change Paragraphp."; } </script> </head> <body> <h2>This is the testing Heading</h2> <p id="demo">A Paragraph.</p> <button type="button" onclick="myFunction()">Try it</button> </body> </html>
In this myFunction is defined in the section of the <head> tag and the JavaScript code is always written in the middle of the <script> tag.
In this document.getElementById is used to get the object of any tag and if you get its value as well.
If we want to do, we see that if there is text then innerHTML or innerText is used to get it.
Note: – Remember that the code of JavaScript is always written above the </body> closing body tag, the code of JavaScript is not written above because the speed of the website is shown to you by writing the code of JavaScript above. Javascript code is loaded after the html and css are loaded.
Request – If you found this post useful for you(how to use where to in javascript), then do not limit it to yourself(how to use where to in javascript), do share it
Nice sir thank u for sharing javascript post please post javascript series
thanku okey daily upload post
okey dear daily upload post