LoginSignup
1
1

More than 5 years have passed since last update.

querySelectorAll 等で取得した NodeList の先頭だけ削除

Last updated at Posted at 2016-07-30

配列の先頭を削除する場合は shift() を使えば良いのですが
配列みたいに使える NodeList(querySelectorAll などで取得)
では shift() が使えなくて悲しい。

特に NodeList に拘りはないので、泥臭くforで先頭だけ消して配列に。
if 使ってコード増えるのも面倒くさいので若干手抜き。

var hoge = document.querySelectorAll("h1");
var newHoge = new Array;

for(var i=1 ; i < hoge.length; i++){
  newHoge.push(hoge[i]);
}

i=0 でなくて i=1 で始めて先頭飛ばした。
他にいい方法ないだろうか。

1
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1