window.dom = {
  find(selector, scope) {
    return (scope || document).querySelectorAll(selector);
  },
  style(node, name, value) {
    if (arguments.length === 3) {
      // dom.style(div,'color')
      node.style[name] = value;
    } else if (arguments.length === 2) {
      if (typeof name === "string") {
        //dom.style(div,'color')
        return node.style[name];
      } else if (name instanceof Object) {
        //dom.style(div,{color: 'red'})
        for (let key inname) { node.style[key] = name[key]; }}}},each(nodeList, fn) {
    for (let i = 0; i < nodeList.length; i++) {
      fn.call(null, nodeList[i]); }}};const div = dom.find("#test>.red") [0]; // Get the corresponding element
dom.style(div, "color"."red"); / / set the div. Style. Color

const divList = dom.find(".red"); // Get multiple div.red elements
dom.each(divList, (n) = > console.log(n)); // Iterate over all the elements in divList

Copy the code