0

Instead of using jQuery all the time, I instead built a String and then tried to parse it to jQuery. However, on IE I got a weird error message for the following snippet. It works fine on Chrome.

$('<tr><td>a</td></tr>');

Using just this results in the following error message on IE:

Object doesn't support this property or method 'getElementsByTagName'

What's going on here? In Chrome, like I said, it works blissfully and just as I would expect, but IE refuses to understand it.

Any clues would be greatly appreciated.

Edit: Even this fails, is it just me having this problem?

$('<td>a</td>');
pimvdb
  • 151,816
  • 78
  • 307
  • 352

3 Answers3

4

You could start with a <table> and .append('<tr>...</tr>') to it, or if it's still empty, use .html('<tr>...</tr>') to fill it.

Matijs
  • 3,118
  • 2
  • 29
  • 41
2

IE8 and under are very particular about TD and TR elements. I do not believe you can create a document fragment (which is what you are doing) containing these types of elements without a parent table element.

Brandon
  • 38,310
  • 8
  • 82
  • 87
1

Perhaps IE is looking for a top level <table> ... </table> to surround the tr and td?

Jason Brant
  • 182
  • 1
  • 11