Checking for presence in jQuery
Using the is method we can check if an element meets a given criterion. If yes, the method returns true, if not - false.
Let's take the following HTML code:
<div>
<input type="text" id="test">
</div>
<p>text</p>
Let's check if the div tag is a parent of our input with #test:
let isDivParent = $('#test').parent().is('div');
alert(isDivParent);
Find all h2, check that among those found there is h2 with class test.
Find all elements immediately following headings. If the element found is a paragraph, append the contents of the heading above it to the end of it.
Find all elements immediately following the headings. If the element found is not a paragraph, insert a paragraph under the heading with the same content as the heading.