Search code examples
javascriptjqueryhtmljquery-after

jQuery .after() not working in IE


I am trying to add a table row to a table using .after() but it's not working in any IE, I keep getting this error "Object required" and the error seems to be coming from line 5151 in my jQuery library.

Here is my code:

$('#view').live('click',function(){
    var parent = $(this).parent();
    parent.after("<tr><td>Test</td></tr>"); 
});

Any ideas?


Solution

  • A likely reason is that the HTML code isn't valid without a table tag.

    Create the elements as separate elements instead:

    parent.after($('<tr/>').append($('<td/>').text('Test')));