Created
July 9, 2012 15:16
-
-
Save 6ui11em/3077106 to your computer and use it in GitHub Desktop.
jQuery: HTML to XHTML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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