0
JavaScript
Bonjour Je me demande comment on intègre du JavaScript dans du html sans passer par le tag script mais avec un <Link> dans <head> comme avec le css ?
7 ответов
+ 4
Vous pouvez lier un fichier js externe comme ceci
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script><!-- Thanks Andrew G for introducing this library -->
<script src="https://unpkg.com/babel-standalone@latest/babel.min.js"></script><!-- Thanks KrOW for the Babel library-->
https://code.sololearn.com/WuNp8CN7AkAe/?ref=app
+ 3
https://code.sololearn.com/WriFNOoR188j/?ref=app
+ 2
Sorry I worry translator will translate wrongly so I need to use English, if you don't understand, I'll ask French such as //Zohir to help.
The above is an example to demo how to retrieve the DOM successfully.
In Vanilla JS, there are
getElementById
getElementsByTagName
getElementsByClassName
Note the s in Elements for the second and third methods, it means that the result is an array, and so you need to use numerical index [0],[1],..etc
Because the code playground JS tab will run before <body>, you need to put the getElement inside window.onload
For CSS, you can style with tag name, id or class name, if a group of element share same style, we use class name instead of id.
+ 1
ok merci
il faut bien sue le code js interagisse avec le code html pour mettre des conditoon par exemple, on intergre les elements html dans js avec les id comme css?
0
ok thank but i see that there is too document.getElementById in the code for put the id like the getElementByTagName, getElementByClassName....
so se can put an id too ?
0
thank’s😊