O'Reilly logo

Beginning JavaScript® and CSS Development with jQuery by Richard York

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 4. Manipulating Content and Attributes

jQuery is a thorough library, and it provides everything you can imagine for working with content from the DOM. In Chapter 2, you saw how jQuery made it really easy to fetch elements from the DOM via its fine-grained support for selecting and filtering selections. Then in Chapter 3, you saw how jQuery built on the W3C event model and made it less verbose while providing more methods that you can use in every browser today. 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. jQuery paves right over these frighteningly verbose and sometimes fragmented methods with a rock-solid API that just works.

In this chapter, I cover 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.

I also cover how you manipulate attributes using jQuery, another area that fringe use cases in some browsers (cough, IE) can make difficult.

Or maybe you've had occasion to want to save custom data with an element, without having to mess around with creating custom attributes or hidden elements. jQuery provides ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required