Assuming that the "lines" are separated by newline characters you can do something like this:
var el = document.getElementById("aoeu"),
content = el.innerHTML.replace(/ |^\s+|\s+$/g,""),
lines = content.split("\n");
That is, get the innerHTML
of the element, remove the leading and trailing whitespace, and then split on the newline character.
Demo: http://jsfiddle.net/RG2WT/
EDIT: Now that you've added <br>
elements (though I'd remove the trailing one):
var el = document.getElementById("aoeu"),
content = el.innerHTML.replace(/^\s+|\s*(<br *\/?>)?\s*$/g,""),
lines = content.split(/\s*<br ?\/?>\s*/);
That is, get the innerHTML
, remove leading and traling whitespace and any trailing <br>
element, and then split on each remaining <br>
element plus the whitespace around it.
Demo: http://jsfiddle.net/RG2WT/3/
Either way lines
will be an array with each element being one of your lines. Either way I'm removing leading and trailing white space so that, e.g., the first item will be "Ammonium NH%4^+"
not " Ammonium NH%4^+ "
.
` between. – nnnnnn Jul 20 '12 at 03:38