Skip to content

Instantly share code, notes, and snippets.

@v9n
Created March 18, 2011 20:52
Show Gist options
  • Select an option

  • Save v9n/876816 to your computer and use it in GitHub Desktop.

Select an option

Save v9n/876816 to your computer and use it in GitHub Desktop.
Fix IE error when getting HTML5 content via XHR
function fixHTML5(content) {
var html5element = ['nav','section', 'header','article','footer'];
var attributes = ['id', 'class'];
$.each(html5element, function (index, tag) {
var re = new RegExp('<(\/?)'+tag+'([^>]*)>', 'g');
content = content.replace(re, '<$1span tag="'+tag+'"$2>');
})
$('#context-panel').html(content);
var fixNode = function (index, tag) {
tag = $(tag);
var node = $('<' +tag.attr('tag') + '/>')
$.each(attributes, function (indexAttb, attb) {
node.attr(attb, tag.attr(attb));
})
node.html(tag.html());
tag.replaceWith(node);
}
$('span[tag]', '#context-panel').each(function (indexSpan, tag) {
fixNode(indexSpan, tag)
});
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment