DOM manipulation methods in a nutshell
The extensive DOM manipulation methods that jQuery provides vary according to their task and their target location. We haven't covered them all here, but most are analogous to the ones we've seen, and more will be discussed in Chapter 12. The following outline can serve as a reminder of which method we can use to accomplish which task:
To create new elements from HTML, use the
$()
function.To insert new element(s) inside every matched element, use:
.append()
.appendTo()
.prepend()
.prependTo()
To insert new element(s) adjacent to every matched element, use:
.after()
.insertAfter()
.before()
.insertBefore()
To insert new element(s) around every matched element, use:
.wrap()
.wrapAll()
.wrapInner()
To replace every matched element with new element(s) or text, use:
.html()
.text()
.replaceAll()
.replaceWith()
To remove element(s) inside every matched element, use:
.empty()
To remove every matched element and descendants from the...