Search code examples
jquerydomgetelementsbytagname

Simple jQuery snippet not working in IE


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>');

Solution

  • 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.