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, Advanced DOM Manipulation. 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
$()
functionTo insert new elements inside every matched element, use the following functions:
.append()
.appendTo()
.prepend()
.prependTo()
To insert new elements adjacent to every matched element, use the following functions:
.after()
.insertAfter()
.before()
.insertBefore()
To insert new elements around every matched element, use the following functions:
.wrap()
.wrapAll()
.wrapInner()
To replace every matched element with new elements or text, use the following functions:
.html()
.text()
.replaceAll()
.replaceWith()
To remove elements inside...