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:

html<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:

javascriptlet isDivParent = $('#test').parent().is('div');
alert(isDivParent);
Задание 1

Find all h2, check that among those found there is h2 with class test.

Задание 2

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.

Задание 3

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.