Сообщение от рони
|
Domik942,
[html run height=500]<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
|
var testHtml = '<head><title>second page</title></head><body><p>test script</p>' +
'<script src="jquery.min.js"></script>' +
'<script>alert("Hello 1");' +
'' +
'$(document).ready(function(){\n' +
' alert(jQuery.fn.jquery);\n' +
'});</script>' +
'<div>the 7 tag</div><div>the 8 tag</div><div>the 9 tag</div></body>';
var parser = new DOMParser();
var doc = parser.parseFromString(testHtml, 'text/html');
var htmlOld = document.querySelector('html');
var htmlNew = doc.querySelector('html');
document.replaceChild(htmlNew, htmlOld);
document.querySelectorAll('script').forEach(el => {
var s = document.createElement('script');
s.text = el.text;
if ((el.src).length > 0){
s.src = el.src;
}
el.parentNode.replaceChild(s, el)
}
)
JS выдаёт ошибку. ReferenceError: $ is not defined.