<h3>header1</h3>
<div>text1</div>
<h3>header2</h3>
<div>text2</div>
let $d = $("div");
let $h = $("h3");
$d.eq(0).attr("id", "first_div");
$h.eq(0).attr("id", "first_h");
$("#first_div").insertBefore("#first_h")
$d.eq(1).attr("id", "second_div");
$h.eq(1).attr("id", "second_h");
$("#second_div").insertBefore("#second_h")