DOM tree manipulation
The .attr()
and .prop()
methods are very powerful tools, and with them we can change the document itself. We still haven't seen ways to change the structure of the document, though. To actually manipulate the DOM tree, we'll need to learn a bit more about the function that lies at the very heart of the jQuery library.
The $() function revisited
From the start of this book, we've been using the $()
function to access elements in a document. As we've seen, this function acts as a factory, producing new jQuery objects that point to the elements described by CSS selectors.
This isn't all that the $()
function can do, however. It also boasts a feature so powerful that it can change not only the visual appearance but also the actual contents of a page. Simply by passing a snippet of HTML code to the function, we can create an entirely new DOM structure from thin air.
Tip
Accessibility reminder
We should keep in mind, once again, the inherent danger in making certain functionality...