Chapter 4Manipulating Content and Attributes
jQuery is thorough; it provides everything you can imagine for working with content in the DOM. In Chapter 2, “Selecting and Filtering,” you saw how jQuery made it easy to fetch elements from the DOM via its fine-grained support for selecting and filtering selections. Then in Chapter 3, “Events,” you saw how jQuery wraps and extends the W3C event model to make it less verbose while also providing vastly more functionality. This chapter continues the discussion of jQuery's API components with an in-depth look at the methods that jQuery makes available for manipulating content and attributes. No longer do you have to worry about whether a browser supports the innerText
or textContent
properties, or the outerHTML
property, or what the standard DOM method of removing an element from a document is. (You should know how to do those things anyway.) jQuery paves right over these verbose and sometimes fragmented methods with a rock-solid API that just works.
This chapter covers how you can shuffle DOM content around, doing things like replacing one element with another, inserting new text or HTML, appending or prepending content, cloning content, and getting rid of content.
It also covers how you manipulate attributes using jQuery, another area that jQuery makes smooth and easy by providing all the methods you'd need to use in the library. Or maybe you've had an occasion to want to save custom data with an element; jQuery provides this, too. ...
Get Web Development with jQuery now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.