javascript - spliting the string into desired format and creating an array out of it -
i have string want break after every </div> , insert array. following string.
"<div title='run of network' id='525000000'>run of network</div> <div title='3dserver11' id='525001499'>3dserver11</div>" i thought of using split() function, since not comma separated string, not able understand how should break string , generate array. in array want single single div entries like:
a[0] = <div title='run of network' id='525000000'>run of network</div> a[1] = <div title='3dserver11' id='525001499'>3dserver11</div>" can 1 help? in advance.
i wouldn't suggest split html strings split method or parse regular expressions. better operate elements dom methods:
var str = "<div title='run of network' id='525000000'>run of network</div>\ <div title='3dserver11' id='525001499'>3dserver11</div>", div = document.createelement("div"), arr = []; div.innerhtml = str; arr = array.prototype.slice.call(div.getelementsbytagname("div")); arr = arr.map(function(e) { return e.outerhtml; }); // create strings // out of dom elements console.log(arr);
Comments
Post a Comment