A Utility To Add CSS Classes To Elements That Match A Query

This function takes a class name and a query string. It applies the former to any element on the page that matches the later. There's nothing special about it other than it prevents having to write the body of the function countless times.

function addClassToQuery(className, query) {
  let els = document.querySelectorAll(query);
  for (let i = 0; i < els.length; i ++) {
    els[i].classList.add(className)
  }
}

Usage

addClassToQuery("highlight", "widgets")
~ fin ~