The after method in jQuery
The after method allows you to add text after elements.
Let's look at the following example, let's say we have a paragraph:
<p>text</p>
Now we write the following Javascript code:
$('p').after('<b>!!!</b>');
After running the code, the paragraph will look like this:
<p>text</p><b>!!!</b>
It should be noted that all of the above insertion methods - prepend, append, before and after also provide the ability to apply a function to each element in the set.
Let's find all the paragraphs and put their serial number in the set at the end of each one:
<p>text</p>
<p>text</p>
<p>text</p>
$('p').append(function(index){return index;});
After each h2, insert '<p>?</p>'.
In one chain, before each h2, insert '<p>!</p>', and after h2 - '<p>?</p>'.