Dino Geek, try to help you

How to use JavaScript with HTML?


Using JavaScript with HTML can be done in two ways: Inline JavaScript and External JavaScript.

1. The first way to use JavaScript in HTML is through Inline JavaScript code, which employs the `script` tag.

Here is an example:
```


Inline JavaScript Example



```
In the example above, JavaScript is written between the `button` element using the `onclick` attribute.

1. The second method is using an External JavaScript, which involves creating a `script.js` file, then include it in your HTML using the `script` tag.

In your `script.js` file, you can write:
```
function displayDate() { document.getElementById(‘demo’).innerHTML = new Date();
}
```

And then, in your HTML file:
```


External JavaScript Example



```
Notice that the `script` tag in this instance has a `src` attribute with the value of the JavaScript file path (either relative or absolute). This method can be used when your JavaScript code is large, and you want to make it modular and easy to manage.

Note: Mostly it is preferred to place scripts at the bottom of the body or using async/defer attributes to prevent blocking of the rendering of the page. However, it can also be placed in the head section or in the body, depending on the needs and behavior expected from the script.


Simply generate articles to optimize your SEO
Simply generate articles to optimize your SEO





DinoGeek offers simple articles on complex technologies

Would you like to be quoted in this article? It's very simple, contact us at dino@eiki.fr

CSS | NodeJS | DNS | DMARC | MAPI | NNTP | htaccess | PHP | HTTPS | Drupal | WEB3 | LLM | Wordpress | TLD | Domain name | IMAP | TCP | NFT | MariaDB | FTP | Zigbee | NMAP | SNMP | SEO | E-Mail | LXC | HTTP | MangoDB | SFTP | RAG | SSH | HTML | ChatGPT API | OSPF | JavaScript | Docker | OpenVZ | ChatGPT | VPS | ZIMBRA | SPF | UDP | Joomla | IPV6 | BGP | Django | Reactjs | DKIM | VMWare | RSYNC | Python | TFTP | Webdav | FAAS | Apache | IPV4 | LDAP | POP3 | SMTP

| Whispers of love (API) | Déclaration d'Amour |






Legal Notice / General Conditions of Use