相关疑难解决方法(0)

JavaScript iterate through NodeList

I am looking for a best way to iterate through NodeList excluding length. I am using:

var foo =  document.querySelectorAll('[id^=foo_id]')
console.log(foo)
Run Code Online (Sandbox Code Playgroud)

Returned NodeList has all the required elements + the last entry of length:.

  0: input#foo_id_...
  1: input#foo_id_...
  ..................
  n: input#foo_id_...
  length: n+1
Run Code Online (Sandbox Code Playgroud)

I wonder what the most efficient way to iterate through that NodeList. I can utilize list length etc, but would like to know if there is a more "elegant" way.

javascript loops nodelist

19
推荐指数
1
解决办法
2万
查看次数

标签 统计

javascript ×1

loops ×1

nodelist ×1