There are sometimes instances where you need to traverse the DOM and gain access to a specific element, or group of elements, but due to certain restrictions, you may not have direct access to the elements via a CSS class name or ID in the HTML code. This might be because of user-generated content produced through a rich text editor, or dynamic content pulled from a database.
As long as you have a map of the general template that contains the element you want to target, you can access that element and manipulate it the same way you would an element that has a class name or ID.
Using the HTML code above, if we wanted to target all the anchor tags on the page, we could collect them and manipulate them like this:. If we wanted to target only the anchor tags in the footer, however, we would target them based on their context, or surrounding elements, like this:. The first line grabs a reference to the footer element.
There is no point in reinventing the wheel.
- Astrophysics in the Next Decade: The James Webb Space Telescope and Concurrent Facilities.
- C# and the .NET Framework: The C++ Perspective;
- The Cooking of Brazil (Super Chef).
- Search Our Blog Articles!
Table of contents
9. JS Advanced Objects
Object Literals to Pass Optional Arguments Here is a handy coding tip to keep in mind when dealing with functions that can accept a large number of optional arguments. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper.
Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Randore March 25, , am 3. Dereje1 March 25, , am 4.
Randore March 25, , am 5. Anyways thank you all. Randore March 29, , am 6. Finally solved the problem, here is the updated code. Why I cannot pass the test? I wrote the same code as yours. Thanks in advance!
Randore June 18, , pm 8. Thanks for your reply!
Here is a part of the code. Randore June 19, , am Hey, this is working fine, I just re-checked the challenge. You can also try destructing the state.