N
N
Nikita2018-07-31 12:32:51
JavaScript
Nikita, 2018-07-31 12:32:51

How to get the value from the block?

Hello everyone, I have a question, how to make a script that will calculate the sum of a column and display it?
for example, the project is done on SharePoint there is a table.
Unfortunately, there is a value here 3 times, the id itself does not have
to somehow pull out the value 70, 20 and 10
as in the screenshot,
src=" https://habrastorage.org/webt/5b/60/2b/5b602bd29c8... " alt="image"/>


and put them into one variable to calculate.
But they are all made statically by type *

<td class="ms-vb-lastCell ms-cellstyle ms-vb2 ms-vb-lastCell">70</td>
<td class="ms-vb-lastCell ms-cellstyle ms-vb2 ms-vb-lastCell">20</td>
<td class="ms-vb-lastCell ms-cellstyle ms-vb2 ms-vb-lastCell">10</td>


I ask you to help me how to identify them and sum them up

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rapen, 2018-07-31
@etozhetisachniy

implementation:

let td = document.getElementsByTagName('td');
let sum = 0;


for(let i = 0; i < td.length; i++){
  sum += +td[i].innerHTML;
}

In general, I recommend studying the DOM

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question