+ 2
Hi guys
How can I change an element of a html file from another file using JavaScript for example,I click on a button in the first html file and the text in the other html file changes
1 Respuesta
+ 1
It sounds like you want to have HTML files pass information to one another.
Some of these options require you to host your website with a web server and will break if you load your HTML from .html files on your file system.
Cookies are one option. Local storage is another. IndexedDB is yet another.
More details are at:
- cookies: https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie
- local storage: https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage
- IndexedDb: https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API
If you really want the other .html to be rewritten with a change, that's not possible with JavaScript that runs in a web browser. JavaScript in a web browser isn't generally capable of writing changes directly to your file system. You'd have to configure something weird or use an extremely insecure browser to write directly to the file system because viruses could be easily spread that way.
This may be of interest to you:
https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Client-side_web_APIs/Client-side_storage