How to get the index of the element in javascript?

后端 未结 5 733
北海茫月
北海茫月 2021-02-07 15:09

The NodeList don\'t have a indexOf(element) method? So, how can I get the element index?

5条回答
  •  执念已碎
    2021-02-07 15:40

    Just add one line in your script:

    NodeList.prototype.indexOf = Array.prototype.indexOf;   // for IE11
    

    Then use indexOf as usual:

    var index = NodeList.indexOf(NodeElement);
    

提交回复
热议问题