is there new syntax regarding of getting dom element
No, because ES2015 ("ES6") is a language standard (which has been superceded by ES2016, ES2017, ES2018, etc.; the latest is always here) that's independent of the DOM, which is a separate standard for the document object model used in browsers.
But note that the DOM has been updated in a couple of ways relatively recently to play more nicely with JavaScript's newer features. I don't think there's any replacement for the verbose document.getElementById
, but for instance, the forEach
on the NodeList
returned by querySelectorAll
that you're using in the quoted code is relatively new (and not supported on any version of IE, though easily polyfilled). Similarly, on a modern browser supporting these recent updates, NodeList
instances are iterable so you can use ES2015's for-of
statement (and other constructs using iterables, such as spread syntax and destructuring):
for (const li of document.querySelectorAll("li.li-class")) {
console.log(li.innerHTML);
}
<ul>
<li class="li-class">one</li>
<li class="li-class">two</li>
<li class="li-class">three</li>
</ul>
That works (on a modern browser) because NodeList
has indexed property getters which means that it's iterable in the JavaScript arena. (For slightly out-of-date environments, this answer shows how to polyfill NodeList
to add forEach
and iterability.)
(Confusingly, the DOM spec has an iterable
declaration that you could reasonably think meant that the DOM collection it's on is iterable. Sadly, that's not what it means. That declaration means it has methods like forEach
, keys
, values
, etc. [like JavaScript arrays do]. Not all iterable DOM collections are marked with the DOM iterable
declaration, because not all iterable DOM collections could safely have those methods added to them for historical reasons. For example, HTMLCollection
is iterable in the JavaScript sense, but isn't marked with the iterable
declaration because it doesn't have those methods.)