0
DOM
how can i select an element's first line in javascript ?
7 ответов
+ 2
const selectFirstElement = document.querySelector('.element:first-child');
+ 2
firstElementChild and children are read only properties, cannot use for update element nodes.
+ 1
there aren't a selector for first line, only for first letter to
if you are looking for first child element you can try with
const container = document.getElementById("myelement");
const first = container.firstElementChild;
or
const container = document.getElementById("myelement");
const first = container.children[0];
+ 1
Calviղ querySelector is not compatible with older browsers. The requisites is only read
https://caniuse.com/?search=querySelector
+ 1
David Ordás how old the browser It's not compatible with? IE8 2008 browser perhaps, does it really matter?
+ 1
Calviղ question to yourself what is the way to maximize posibilities and the answer to it is got
of course always can be patched using polyfills to this residual browsers
+ 1
David Ordás Most web developers would ignore support of very old browsers like ie8, which literally has no user using it now.
Of course you could add polyfills to support it, if your project really need to support over 10 years old browsers, but I believe it's rare case, you only add the unnecessary code there, even though polyfills would not affect new browsers performance too much.