添加 DOM
.after(content, [content, ...])
将 content 插入到某元素的后面,并作为其后面第一个兄弟节点。
$('.apple').after('<li class = "plum">Plum</li>');
$.html();
//=> <ul id = "fruits">
// <li class = "apple">Apple</li>
// <li class = "plum">Plum</li>
// <li class = "orange">Orange</li>
// <li class = "pear">Pear</li>
// </ul>
.before(content, [content, ...])
将 content 插入到某元素的前面,并作为其前面的第一个兄弟节点。
$('.apple').before('<li class = "plum">Plum</li>');
$.html();
//=> <ul id = "fruits">
// <li class = "plum">Plum</li>
// <li class = "apple">Apple</li>
// <li class = "orange">Orange</li>
// <li class = "pear">Pear</li>
// </ul>