Prevent jQuery .html() from removing self closing tag slash -


i'm sure of know following:

var str = '<img src="path/to/some/image" />'  $('#selector').html(str); 

this output following html:

<div id="selector">   <img src="path/to/some/image"> </div> 

it removes self closing "slash" @ end of img tag because jquery renders true html, not xhtml.

my hands tied using cms validates against xhtml markup copied or created in systems wysiwyg must contain "slash" @ end of self closing tag.

my predicament using bootstrap form builder create quick , dirty forms. application uses jquery .html() create rendered html. < input > closing tag slashes being stripped. when copy , paste rendered code cms, won't let me published it.

anybody have clever way prevent .html() removing "slashes"? or @ least putting slashes in without having manually it?

if read the documentation see following text:

this method uses browser's innerhtml property. browsers may not generate dom replicates html source provided. example, internet explorer prior version 8 convert href properties on links absolute urls, , internet explorer prior version 9 not correctly handle html5 elements without addition of separate compatibility layer.

this makes me believe problem browser using, rather problem jquery.

you can possibly use tidy turn valid xhtml. googling makes me think this tool might able you.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -