I wanna provide you with a nice utility for quick summing of multiple DOM element values. Why? Well, suppose you’ve at a page like this and you want to sum up the total number of hotels in all the countries. 

The JavaScript code

So open the page given and open your browser’s Dev tools (it’s F12 on PCs, Preferences -> Advanced -> Show Develop menu on Mac). Once they are open, go to Console (Console tab) and enter the following code:

Now based on the Dom element class attributes you again enter into the console:

Full picture with results
main script

Youtube channel views counter

One possible use case for this method would be to count a youtube video channel’s total views. Let’s sum up the channel’s total number of views.

  1. Pick the xxx views (number of views for a single video) page element and find it in the DOM inspector (right click on target element -> Inspect element).
    dom counter inspect
    The element of interest is the 2-nd li tag having ul parent tag with yt-lockup-meta-info class. See inspector picture below. youtube selector
  2. Now you insert in the browser console the above JavaScript and after that hit the following line in the console:

It’s important to not that the info notation to those videos should be in the following format: publishing date • number of views. The number of views should stand after the publishing date. See how:

dom counter videoIf their order is opposite, use the following domCounter() call:

Bookmarklet

I’ve composed a Chrome bookmarklet that quickly counts total views of a YouTube channel and pops the number up for you to copy/paste.

You can quickly try it on my youtube channel (for Google Chrome or FireFox). Have this useful sum up utility for your convenience.

Acknowledgement

The Dom counter code has been graciously provided to us by Adrian Balcan from thewebminer.com. You can track any updates here.