Posted By

localhorst on 01/26/11


Tagged

innershivshivhtml5jqueryIE


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

JoF


html5 / jQuery innerHTML fix for IE


 / Published in: JavaScript
 

URL: http://jdbartlett.github.com/innershiv

If you try to access innerHTML of HTML5 elements like or or even just the #foo id then IE returns nothing innerShiv solves this.

  1. // http://jdbartlett.github.com/innershiv | WTFPL License
  2. window.innerShiv = (function() {
  3. var d, r;
  4.  
  5. return function(h, u) {
  6. if (!d) {
  7. d = document.createElement('div');
  8. r = document.createDocumentFragment();
  9. /*@cc_on d.style.display = 'none';@*/
  10. }
  11.  
  12. var e = d.cloneNode(true);
  13. /*@cc_on document.body.appendChild(e);@*/
  14. e.innerHTML = h.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
  15. /*@cc_on document.body.removeChild(e);@*/
  16.  
  17. if (u === false) return e.childNodes;
  18.  
  19. var f = r.cloneNode(true), i = e.childNodes.length;
  20. while (i--) f.appendChild(e.firstChild);
  21.  
  22. return f;
  23. }
  24. }());

Report this snippet  

You need to login to post a comment.