+ 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
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"
+ 2
thank you