Created
March 18, 2011 20:52
-
-
Save v9n/876816 to your computer and use it in GitHub Desktop.
Fix IE error when getting HTML5 content via XHR
This file contains hidden or 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
| 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