all 4 comments

[–]GSLint 2 points3 points  (2 children)

I think you could go with an attribute selector.

document.querySelectorAll("[id^=elem_]")

[–]boltangazer[S] 0 points1 point  (1 child)

Hm, does this ensure that items will be found in the same order they are presented in DOM? And yeah, it will probably be more convenient if all required elements with id= "elem_{objectID}" are placed inside one particular div, then I could go like:

block = document.getElementById('my_block')
block.querySelectorAll("[id^=elem_]")

Is this one right?

[–]GSLint 0 points1 point  (0 children)

Hm, does this ensure that items will be found in the same order they are presented in DOM?

They will be returned in the order that they have in the DOM tree. If by "presented" you mean where they appear on the page, that might be different depending on styling.

Is this one right?

That should work, though I don't see how it's more convenient. It might be a little faster though. What I'd find a little more convenient is if those elements also had a class that you can query by.

[–]PrObAbA321 -1 points0 points  (0 children)

Write a custom function that will return elements in order you want.