1.
<script>
2. [Link]("Hello JavaScript by JavaScript");
3. </script>
Places to put JavaScript code
1. Between the body tag of html
2. Between the head tag of html
3. In .js file (external javaScript)
4. <html>
5. <body>
6. <script type="text/javascript">
7. alert("Hello Javatpoint");
8. </script>
9. </body>
10. </html> <html>
11. <head>
12. <script type="text/javascript">
13. function msg(){
14. alert("Hello Javatpoint");
15. }
16. </script>
17. </head>
18. <body>
19. <p>Welcome to Javascript</p>
20. <form>
21. <input type="button" value="click" onclick="msg()"/>
22. </form>
23. </body>
24. </html>
The script tag specifies that we are using JavaScript.
The text/javascript is the content type that provides information to the
browser about the data.
The [Link]() function is used to display dynamic content
through JavaScript. We will learn about document object in detail later.
Javascript - [Link]()
method
The [Link]() method returns the element of specified
id.
1. <script type="text/javascript">
2. function getcube(){
3. var number=[Link]("number").value;
4. alert(number*number*number);
5. }
6. </script>
7. <form>
8. Enter No:<input type="text" id="number" name="number"/><br/>
9. <input type="button" value="cube" onclick="getcube()"/>
10. </form>