apv
10-18-2006, 10:00 PM
I'm scripting a little utility much like Alex King's wonderful little js_quicktags. I thought it would make more sense (and be more compact, easier to manipulate, etc) to use the DOM directly to create the tags instead of cobbling together plain text HTML.
It works but the literal tags brought back are not XHTML (even when the parent document is XHTML strict; I suppose it only matters for standalone tags like img and br). I've only tested in FireFox and Safari so far.
Here is a minimal script to show the problem:
var container = document.createElement('div');
var tag = document.createElement('br');
container.appendChild(tag);
alert(container.innerHTML);
The alert text should be "<br/>" or "<br />." But in FireFox it is "<br>" and in Safari it is "<BR />."
I've searched around but can't find ways to manipulate/control the DOM or whatever would be necessary to get the right output.
Ideas? Or is it just not really feasible to do compactly (meaning Alex's approach is best)?
Thank you!
It works but the literal tags brought back are not XHTML (even when the parent document is XHTML strict; I suppose it only matters for standalone tags like img and br). I've only tested in FireFox and Safari so far.
Here is a minimal script to show the problem:
var container = document.createElement('div');
var tag = document.createElement('br');
container.appendChild(tag);
alert(container.innerHTML);
The alert text should be "<br/>" or "<br />." But in FireFox it is "<br>" and in Safari it is "<BR />."
I've searched around but can't find ways to manipulate/control the DOM or whatever would be necessary to get the right output.
Ideas? Or is it just not really feasible to do compactly (meaning Alex's approach is best)?
Thank you!