Skip to content
Advertisement

Count specific value in table in javascript

I’m newbie and having a trouble on how can I count the number of value 1 and value 2 under the header 2 based on the image I attached. So the result of value 1 should be 2 and the value 2 should also 2 Is there any trick how can I solve this, Im new with this,I hope anyone can help.

enter image description here

This is what I tried my html

JavaScript
JavaScript

Advertisement

Answer

Here’s an option – just grab all elements with the class you have set on the second-column elements ("count_value"), and check if the text in those elements (elem.innerText) contains a "1" or "2".

JavaScript
JavaScript
Advertisement