So youâ€™ve been playing with jQuery for a while now, youâ€™re starting to get the hang of it, and youâ€™re really liking it! Are you ready to take your jQuery knowledge to level two? Today, Iâ€™ll demonstrate twenty functions and features you probably havenâ€™t seen before!
1 after() / before()
Sometimes you want to insert something into the DOM, but you donâ€™t have any good hooks to do it with;
prepend() arenâ€™t going to cut it and you donâ€™t want to add an extra element or id. These two functions might be what you need. They allow you to insert elements into the DOM just before or after another element, so the new element is a sibling of the older one.
$('#child').after($('<p />')).text('This becomes a sibling of #child')); $('#child').before($('<p />')).text('Same here, but this is go about #child'));