On Dec 10, 3:24 am, "T.J. Simmons" <theimmortal...@gmail.com> wrote:
> Yeah, I wasn't really sure it would work, but thought it was worth a try.
>
> And the <br/> <br> thing I think depends on the browser used and the
> rendering mode it's forced into. What doctype are you using?
>
> And for some more thought, Firefox (using <!doctype html>) renders <br> as
> <br>, but IE8 will show them as <BR>, so.. see what you're getting and do a
> replace on all possible combos, that's my thought.

So by trying to use an inappropriate method, you slowly build
increasing complexity where there should be none. If the intention is
to collect text nodes and replace BR nodes with new lines, then:

function specialGetText(el) {
  var text = '',
      node,
      nodes = el.childNodes;
  for (var i=0, iLen=nodes.length; i<iLen; i++) {
    node = nodes[i];
    if (node.nodeType == 3) {
      text += node.data;
    } else if (node.tagName.toLowerCase() == 'br') {
      text += '\n';
    }
  }
  return text;
}

Should do the job.


--
Rob

Reply via email to