Usually css and javascript are connected like this.

<head> <meta charset="UTF-8"> <title>Nexus</title> <link rel="stylesheet" type="text/css" href="style/global.css"> <link rel="stylesheet" type="text/css" href="style/load.css"> <script src="javascript/librarie.js"></script> <script src="javascript/load.js"></script> <script src="javascript/req.js"></script> </head> 

But is it possible to connect them in any other tag?

for example inside <body> in <div> :

 <div id='head'> <link rel="stylesheet" type="text/css" href="style/global.css"> <link rel="stylesheet" type="text/css" href="style/load.css"> <script src="javascript/librarie.js"></script> <script src="javascript/load.js"></script> <script src="javascript/req.js"></script> </div> 

If this is possible, in which tag is it better to do this and can there be any problems with such a connection?

    1 answer 1

    JavaScript works with the DOM document model html, the DOM model is formed until all the html is loaded, you can connect JS anywhere, but this is not recommended, and for that matter, you need to connect before the closing body tag. That is, after all the content, as it must load to form a DOM model.

    UPD: I forgot about the styles.

    Styles can be connected only in the head tag. As defined in the specification.

    • and if I need to, as the site works (without reloading the page), remove and add styles and javascript libraries to the site, how can it be fixed so that the user doesn’t notice anything? - Kirpich643 13:16
    • Describe your task better. Initially, something is not in your plans =) - Gena Ant
    • I make a website like a desktop and there dafiga styles and libraries accumulate and I got the idea to remove unnecessary styles and libraries is it bad? - Kirpich643
    • It is perfectly! Use conditions (if, else, switch) to display the necessary styles and libraries depending on the page. =) - Gena Ant