Home > OS >  why script and div tag could much in html ,bug html and body tag only one
why script and div tag could much in html ,bug html and body tag only one

Time:11-08

Nice to meet u ,my friend I had find in baidu.com ,cnds,stack overflow,but cannot get answer. I have two question "why script and div tag could much in html",other is "why html and body tag only one in html" Such as

<!DOCTYPE html>
<html lang="en">
<head>
</head>
<head>
</head>
<head>
</head>
<head>
</head>

<body></body>
<body></body>
<body></body>
<body></body>

</html>

can`t be work

But

<!DOCTYPE html>
<html lang="en">

<head>
    <script type="text/javascript">
        document.write("Hello World!")
    </script>
    <script type="text/javascript">
        document.write("Hello World!")
    </script>
    <script type="text/javascript">
        document.write("Hello World!")
    </script>
    <script type="text/javascript">
        document.write("Hello World!")
    </script>
    <script type="text/javascript">
        document.write("Hello World!")
    </script>
</head>

<body></body>

</html>

can be work

Because in the browsers base code? Please tell me why ,thank you very much Your`s friend zt :)

CodePudding user response:

The HTML specification (unfortunately not transcribed into all languages) might help you out.

Basically an HTML page is structured like a tree.

<html>
  <head>
    // ..metadata, CSS, JS
  </head>
  <body>
    // document elements here
  </body>
</html>
 

The main HTML document can have only one <head> and one <body> element.

<head> includes meta-data, links to CSS, and often - but not always - links to JS scripts and, depending on the app you're creating, there may be lots of CSS and JS. They maybe links to scripts or CSS you've created, or links to scripts or links online, maybe stored in a open-source CDN.

<body> will contain the general markup for the page - all of the elements, the headings, sections, paragraphs etc will be here. It may also contain links to scripts too because sometimes those scripts rely on the document, and its elements, to be loaded first before they can be executed properly.

I suggest trying to read up on some documentation which has been translated into a few languages and small tutorials on how to make an HTML page first though. As you learn, you'll start to understand.

  • Related