Examples of using JavaScript code in HTML code

  • 2020-03-30 04:06:44
  • OfStack

< Script> < / script> The label

To use JavaScript in HTML, use < Script> < / script> Tag, and define the type attribute value to be text/javascript, as shown in the previous (link: #) example:


<script type="text/javascript">
alert(" I'm the prompt! ");
</script>

Usually JavaScript code alone doesn't make sense. JavaScript code is often used in conjunction with HTML code, because JavaScript is designed to compensate for HTML's shortcomings. Here is an example of JavaScript code used with HTML code:


<html>
<head>
<script type="text/javascript">
alert(" I'm the prompt! ");
</script>
</head>
<body>
<div> Pictures and text content </div>
</body>
</html>

In general, JavaScript code (< Script> < / script> Label) placed at < Head> < / head> Within the tag, see "(link: #)" for more details.


Related articles: