javascript - Append elements in a variable instead of a temporary DOM -
Is it possible to create something like "DOM" in a variable? Right now I am making a temporary divi container, so I can add my results to the right elements. After this I remove the temporary container.
But is this really necessary?
Firstly I parse an HTML-string. After that, I create a section-box (if the content matches a keyword-array) and insert some content into that section-box, how the code is working.
var element = $ .parse HTML (input_string); Var keyword = ['keyword1', 'keyword2']; Var current = 0; $ ("Body"). Endend (' ';); // & lt; - $ .each (Element, Function (index, element) {var z = element.innerHTML.trim (); if ($ .inArray (z, keyword)! == -1) {$ ("(* * & Lt; Section class = "box"> '+ z +' ;); existing = 1;} and (existing)? Add ('& lt; p & gt;' + z + '&' & lt; p & gt; + + z + '& lt; / p & gt;'): $ ("# temp") Lt; / p & gt; ';)}}) Var result = $ ("# temporary"). Delete HTML (); $ ("# temporary");;
you can,
var elements = $. HTML (input_string); var keyword = ['keyword1', 'keyword2']; var current = 0; // Do not make the skin but add $$$ ($ 'id = "temp" & gt; & lt; / div & gt;' '); $ .eu (element, function (index, element) {Var z = element.innerHTML.trim (); if ($ .inArray (z, keyword)! == -1) {// Use temp variable instead of domain temp object $ temp.append ('& lt; Section class = "box"> gt; & lt; h1 & gt; '+ z +' & lt; / H1> & Lt; / Section & gt; '); Existing = 1;} and ((& lt; p & gt; '+ z +' & lt; / p & gt; '): $ temp.append (' & lt; p & gt; '+ [* b * R. *] [Current]? $ Temp.find (". Box: last" Z + '';)}}); result result = $ temp.html (); But I recommend using plain string combinations if you do quickly
Comments
Post a Comment