JSFiddle - React, Tailwind, and code Playground

HTML

<div id="elID">This is is a a a test test test test</div>

JavaScript

const myElementText = document.getElementById("elID").textContent; 

let counter = str => {
  return str.split(' ').reduce((total, word) => {
    total[word] ? total[word]++ : total[word] = 1;
    return total;
  }, {});
};
console.log(counter(myElementText));