如何在类中搜索ID,每次重新加载页面时ID都会更改

时间:2019-02-21 19:52:33

标签: javascript

document.getElementByClassName('_2hvTZ pexuQ zyHYP')
每次重新加载页面时,班级中的id都会更改。我需要在类f中找到ID,如下所示,其中ID保持不变,如下所示,其中包含一些ID。该类保持不变,因此如何每次都在我的类中找到新的ID。我想使用Javascript RAW

f19c49e0e618e18 f8ca3372aa0bd8 f5c32cc227cf38

1 个答案:

答案 0 :(得分:0)

// We're going to get all the elements and force them into an array,
//  rather than a nodeList. That's what the [... and ] are doing to
//  our selector.
let myElements = [...document.getElementsByClassName('_2hvTZ pexuQ zyHYP')],
    arrayOfIds =  [];

// We can now use each member of myElements in a forEach. Within that,
//  the current member is called 'element'. So we can see its ID, and do
//  whatever we need to do with that.
myElements.forEach(function (element){ arrayOfIds.push(element.id);} );

console.log(arrayOfIds)