
Why I have ditched the QuerySelector
Why? The 'document.querySelector()' has many downfalls. There are many articles on the web to read more about it! As I work the Javascript OOP way, I don't need it. What I do instead and what I want to share here is this: Connecting to the DOM directly. What I do is making use of already available object keys in the dom tree: document.activeElement (in callbacks and aside of event.target) firstElementChild lastElementChild children length nextElementSibling parentElement previousElementSibling Some Wisdom first: If a parent element has just one child element. The values of 'firstElementChild' and 'lastElementChild' are equal. This means that 'lastElementChild' can be used too! ☛ Bad practice, because if there is a new element to be added at a later stage then things are broken. ☛ Good practice is just to stick to 'firstElementChild' and leave 'lastElementChild' free for future use. How do I do that? It's about creating a central point to work from. Next is to create the objects out of
Continue reading on Dev.to
Opens in a new tab



