Domik941,
возможный вариант ...
<html>
<head>
<title>test js page</title>
</head>
<body>
<script>alert("hello 111");</script>
<div>the 1 tag</div>
<div>the 2 tag</div>
<div>the 3 tag</div>
<script>
var testHtml = '<p>test script<\/p><script>alert("hello 222");<\/script>';
var parser = new DOMParser();
var doc = parser.parseFromString(testHtml, "text/html");
var div = document.querySelectorAll('div')[2];
div.innerHTML = "";
[...doc.body.children].forEach(el => {
if(el.tagName == "SCRIPT") {
var s = document.createElement('script');
s.type = "text/javascript";
s.text = el.text;
el = s;
}
div.append(el);
} )
</script>
<div>the 4 tag</div>
<div>the 5 tag</div>
<div>the 6 tag</div>
</body>
</html>