Skip to content

Instantly share code, notes, and snippets.

@6ui11em
Created July 9, 2012 15:16
Show Gist options
  • Save 6ui11em/3077106 to your computer and use it in GitHub Desktop.
Save 6ui11em/3077106 to your computer and use it in GitHub Desktop.
jQuery: HTML to XHTML
var html = jQuery('#html-element').val();
if (html != '') {
html = jQuery(html).get(0);
var xhtml = getXHTML(html);
jQuery(this).val(jQuery(xhtml).get(0).outerHTML);
}
function getXHTML(node) {
jQuery.each(node.attributes, function(i, attrib){
var name = attrib.name;
var value = attrib.value;
if (value == '')
attrib.value = '1';
});
return node
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment