Web Development with jQuery®

(Elliott) #1

Removing Content (^) ❘ 129
$('h4, table').remove();
}
);
}
);
Figure 4-19 shows the result of the preceding example.


FIGURE 4-19


The preceding example shows what happens when you use jQuery’s empty() method. This is essen-


tially the same as passing an empty string to the html() method—all the element’s children elements,


whether HTML elements or text, are removed.


The preceding example also demonstrates jQuery’s remove() method, which deletes the items specifi ed


in the selection. It should be noted, however, that those items still exist within jQuery, and you can


continue to work with those items by chaining subsequent jQuery methods to the remove() method.


You can also pass a selector to the remove() method, which acts as a fi lter. Any items specifi ed in a


selector provided to the remove() method are preserved and are not removed from the document.


http://www.it-ebooks.info

Free download pdf