cycling jQuery_Succinctly | Page 57

// That is how the replace() string method is chained after using text() })(jQuery); You could also update any characters that are contained in a string returned from html(). This means you can not only update text, but also update and replace DOM elements via a regular expression. Grokking the .contents() method The .contents() method can be used to find all the child element nodes, including text nodes contained inside of an element. However, there is a catch. If the retrieved contents contain only text nodes, the selection will be placed inside the wrapper set as a single text node. However, if the contents you are retrieving have one or more element nodes amongst the text nodes, then the .contents() method will contain text nodes and element nodes. Examine the code below to grasp this concept. Sample: sample48.html

I love using jQuery!

I love really using jQuery!

Notice that when an item in the wrapper set is a text node, we have to extract the value by using .get(0).nodeValue. The contents() method is handy for extracting text node values. It is possible to extract only the text nodes from a DOM structure using contents(). 57