getByClassName

Эта функция будет искать в DOM все элементы с заданным именем класса и возвращать массив этих элементов.

function getByClassName(className) {
  const elementsWithClassName = [];

  // Get all elements in the DOM
  const allElements = document.getElementsByTagName("*");

  // Loop through all elements and check if they have the specified class
  for (let i = 0; i < allElements.length; i++) {
    const element = allElements[i];

    // Check if the element has the specified class
    if (element.classList.contains(className)) {
      elementsWithClassName.push(element);
    }
  }

  return elementsWithClassName;
}

// Usage
const elements = getByClassName("example-class");

// Now 'elements' contains an array of DOM elements with the class "example-class"

Спасибо за прочтение

Я знаю, что всегда есть что улучшить. Пожалуйста, поделитесь своими мыслями