Let's now talk about accessing and updating text nodes and attribute fields.
First we must select the element that contains the particular text node we want to edit. We can store its reference into a variable, and use the
firstChild property to access its text element. Any text within any of our element's children will not be included.
The text of the text node can be accessed using its only property,
nodeValue. Through this variable, we may access or update the text node.
var item = querySelector('li'); itemText = item.firstChild; itemText.nodeValue;
nodeValue property simply returns the content of the node.
Another approach is the use
innerHTML, which obtains all the text and markup inside of an element. This will access all child elements and the text content within.
innerHTML should not be used, as it is not considered a standard by the W3C.
The standard way to accessing text is through the
Setting this node will remove all child elements within, and replace it with the given text.
textContent is more powerful than
innerHTML, since HTML elements are not parsed; this allows you to to write HTML character within an element.
As you should recall, attributes are the properties given to an HTML element. For example, the anchor tag (
<a href=""></a>) should always have an
href attribute. Let's now look at the methods that are used to access, modify and update these attributes.
a, otherwise False.
aattribute from the element.
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