Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Template tag polyfill for IE 11 - not working with table tr and td

I work with polyfill js that allows to process tags for browsers that does not support it.

Source code of polyfill on jsfiddle

Source question

But I've noticed that in IE 11 this polyfill fails to work with templates that include <tr> and <td> tags

My sample on jsfiddle

The problem is that when we try to get childNodes from template tag node

elPlate.childNodes

it returns everything but <tr> and <td> children as if there were no such tags inside <template>.

Am I missing something? Is there any workarounds for this issue?

P.S I was not able to add a comment to source issue due to lack of reputation. Sorry for that.

like image 366
Gintonic Avatar asked Feb 11 '23 19:02

Gintonic


1 Answers

This is happening because <tr> must be inside a <table> in order to be valid HTML. In your <template>, you have specified a loose <tr> that doesn't have a <table> parent. IE sees this as an error and removes it from the DOM. Hence, your template's documentFragment does not contain the <tr> and <td>.

The unfortunate fact is: IE is simply not ready for HTML5 template tags. It'd probably take a loooong while for Microsoft to implement it, and for the existing IE browser versions become truly obsolete. Only then can we reliably start using HTML5 template tags.

The workaround is: do not use <template>; explore template solutions using <script type="template"> instead. I believe they should work well. Some popular ones:

  • https://mustache.github.io/
  • http://handlebarsjs.com/
like image 171
light Avatar answered Feb 15 '23 11:02

light