When selecting elements from the DOM, we can either select one or many nodes. Let's start with retrieving a single element.
The most efficient way to obtain an element is through its
id attribute. We may do this with the
getElementById() method, in which we simply pass in the name of the
id. Since we know that no two elements can share the same
id, we are ensured that the browser terminates right after finding the first
id, resulting in quickness and responsivity.
var firstItem = document.getElementById('first')
This command will store the reference to the element with an
first within the
Another way to select just one element is through a query selector. Given a CSS selector, this returns only the first matched item.
firstParagraph = document.querySelector('p') # First
tag. document.querySelector('.item') # First element with a class "item"
Once we have selected a single element, we may access the nodes around it through these properties:
This book teaches HTML as if it's for anyone - hobbyists, students, and professionals - and it's full-color throughout. It utilizes information graphics and lifestyle photography to explain the topics in a simple way that is engaging. You can progress through the chapters from beginning to end or just dip into topics of particular interest at your leisure.$ Check price
Relieve spasms, tight muscles, trigger points and pressure points with the Body Back Buddy! This trigger point massage is designed to help you self-message any area of your body - especially those that are hard to reach. Keeping your muscles relaxes and out of contraction is importan in helping to reduce pain and prevent muscle injury.$ Check price