Answer the question
In order to leave comments, you need to log in
How to write html code to json?
How to implement line-by-line writing of html code in JSON? On JS
For example, I have a full-fledged page code, I need to write it all line by line In JSON. How can i do this? Help with advice or example
Answer the question
In order to leave comments, you need to log in
You need to escape some characters, depending on where exactly you plan to use this JSON, the set of these characters may differ.
const foo1 = {"key":"<h1>Hello</h1>"} // valid
const foo2 = {"key":"<h1 id="zzz">Hello</h1>"} // invalid
const foo3 = {"key":"<h1 id=\"zzz\">Hello</h1>"} // valid
function textNodesUnder(el){
var n, a=[], walk=document.createTreeWalker(el,NodeFilter.SHOW_ELEMENT,null,false);
while(n=walk.nextNode()) a.push(n);
return a;
}
textNodesUnder(document.body)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question