So far, this chapter's phrases have covered both regular tags and text nodes. The one major thing still missing is attributes. You can access attributes in the form of nodes, but the most convenient way is to use the setAttribute() method: Just provide the attribute name and its value. In the following code, the contents of the new <li> items are a hyperlink, with an HRef attribute set: Setting Attributes (attributes.html)
Figure 5.5 shows that all links added to the list do point to the provided URL. Figure 5.5. Dynamically generated hyperlinks.![]() |