Skip to content
Advertisement

it’s possible to obtain the data stored in a label label to assign it to another variable and thus be able to graph it?

my label

Porcentaje:

here I am adding the result of my operation to the label
document.getElementById(“percentage1”).innerHTML = perc1 + “%”;

I am trying to assign it to another variable the value of the label let PorcElement6 = document.getElementById(“percentage1”).label;

I am trying to add that variable to the graph data: [PorcElement6, PorcElement7, PorcElement8, PorcElement9, PorcElement10],

Advertisement

Answer

Read it with .innerText, for example:

<label id="percentage1">44.3%</label>
const labelElement = document.getElementById("percentage1");

const text  = labelElement.innerText; // "44.3%"
const int   = parseInt(labelElement.innerText, 10); // 44
const float = parseFloat(labelElement.innerText); // 44.3
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement