In other cases, it is better to write the code in a separate js-file and include it on the necessary pages. It is desirable to minimize all code on production sites, and if there are a lot of files with scripts, it would be a good practice to combine such files into one and then connect it to the page. This approach will significantly speed up the loading of your pages. Download speed can be viewed in the browser console in the network tab or use services like Goggle PageSpeed .
It will be correct to register classes for tags, in the class attribute , and access the elements from the js-code placed in the file. Sometimes you can write identifiers, id attribute of the tag. But classes are preferable, as this way you can also use them in css .
Elements (selectors) are accessed using 6 basic methods for finding DOM elements: getElementById , getElementsByName , getElementsByTagName , getElementsByClassName , querySelector , querySelectorAll . Thus, having found an element on the page, you can set a handler for it, delete the element itself, change its properties, etc., that is, give the page interactivity, animate it.
- 09.07.22IT / Misc Convert office files DOC, DOCX, DOCM, RTF to DOCX, DOCM, DOC, RTF, PDF, HTML, XML, TXT formats without loss and markup changes
- 07.07.22IT / Safety How to protect PHP, JS, HTML, CSS source code - obfuscation, minification, compression and encryption
- 06.07.22IT / Safety Connection not secure, problem with Lets Encrypt - how to fix expired 09/30/2021 DST Root CA X3, remove it manually and install ISRG Root X1. Example on MS Windows 7
- 08.07.21IT / Misc How to make a free translation for a website without an API, translate documents in Google Translate
- 06.07.21IT / Misc How to make a subscription button on a website, a subscriber base and automatic mailing