Get HTMLElement from Element

前端 未结 4 676
孤街浪徒
孤街浪徒 2021-01-07 16:58

I have an Element, and I can not figure out how to get the HTMLElement from it.

For example:

A link         


        
4条回答
  •  终归单人心
    2021-01-07 17:25

    You're close!

    var nodes = document.querySelectorAll('a'); // Returns a NodeList of Elements
    for (let i = 0; nodes[i]; i++) {
        // node is your element!
        var node = nodes[i];
        node.style.backgroundColor = "blue";
    }
    

提交回复
热议问题