Skip to content

$: getDom - 获取 Dom 节点

使用

js
import { $ } from 'iflyjs'
console.log($('#test')) // output: div node

源码

ts
function $(selector: string) {
  const nodes = document.querySelectorAll(selector)
  if (nodes.length === 0) {
    return undefined
  }
  if (nodes.length === 1) {
    return nodes[0]
  }
  return nodes
}

Released under the MIT License.