+ 1
moving variables between js and html
if I have a variable declared in the js section how can I use the this variabe in the html code
4 Respuestas
+ 2
could you provide your use case to better understand what you wantvto achieve?
(it's not clear, because html doesn't handle variables ^^)
+ 2
you must get a reference of the targeted element in wich you want display the value (as text) an assign it to its 'textContent' property (or innerHTML if you need to provide html code to be parsed) for most of elements: for input/form elements the property to assign is usually 'value'...
the easiest way to get a reference is to use querySelector or querySelectorAll methods (wich get a query string argument -- css selectors syntax), either on document or on another element (wich will be used as root for searching in childs at any level).
https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector
https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll
0
I know that html doesn't handle variables so i'm asking how can I use some variables declared in the js script for showing them in the web page using the html.
like this: I have a web project in the code editor of sololearn and in the js section I have declared a variable named "post". How I can show the value of variable in the web page (html manage the web page that's why i'm asking how can I show variables in html but declared in js)
0
Ok, thanks