Unique element ID, even if element doesn't have one

前端 未结 13 1253
抹茶落季
抹茶落季 2020-12-14 00:43

I\'m writing a GreaseMonkey script where I\'m iterating through a bunch of elements. For each element, I need a string ID that I can use to reference that element later. The

13条回答
  •  不知归路
    2020-12-14 01:08

    If you're not modifying the DOM you can get them all by indexed order:

    (Prototype example)

    myNodes = document.body.descendants()
    alert(document.body.descendants()[1].innerHTML)
    

    You could loop through all of the nodes and give them a unique className that you could later select easily.

提交回复
热议问题