+ 2

How to collect a information from a label and place it in a variable

Can somebody help me? I want know how to get information that is on a label, and after that make it become the information of a variable

2nd Aug 2020, 6:32 AM
Matheus Forte Maciel
Matheus Forte Maciel - avatar
3 odpowiedzi
+ 6
add an id to the label and then use function innerText to get it's text example: <label id="lbl" > New Label</label> <script> let labelContent = document.querySelector("#lbl").innerText; console.log(labelContent); </script> note: if the html element is label, p, div, span, etc any element which has text just printed as it is . then we use innerText or innerHTML but when it is a textarea, input, checkbox etc then we use "value"
2nd Aug 2020, 6:43 AM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
+ 2
thank you
2nd Aug 2020, 7:40 AM
Matheus Forte Maciel
Matheus Forte Maciel - avatar