Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Object doesn't support property or method 'append' in IE9

this script is working in firefox or chrome but only gets half way in IE9 which is the top browser for our websites.

the problem im getting is its throwing this error.

SCRIPT438: Object doesn't support property or method 'append' calc_ajax.js, line 26 character 21

on this line: item.append(link);

and im stuck why. any help would be appreciated.

$(document).ready(function(){
$('.first a.btn').click(function(){
    $('.first a.active').removeClass('active');
    $(this).addClass('active');
    $('.second .title').addClass('active');

    var id = $(this).data('cat-id');

    var wrap = $('<div>');

    $.ajax({
        url:    script_url,
        type:   "post",
        data: {"cat": id},
        dataType: "json"
    }).success(function(result){
        if(result.status == "ok"){
            $.each(result.data, function(i, elem){
                item = $("<div class='body-area'>").append($("<img src='" + elem.image + "'>"));
                link = $("<a href='#results' class='btn'>");
                link.text(elem.name);
                link.data('subcat-id', elem.id);
                item.append(link);

                wrap.append(item);

            });
            $('.second .body').html(wrap).slideDown('fast');
        }
    });
});

$('.second a.btn').live('click', function(){
    $('.second .body-area.active').removeClass('active');
    $(this).parent().addClass('active');

    var sub_id = $(this).data('subcat-id');        

    $.ajax({
        url:    script_url,
        type:   "post",
        data: {"subcat": sub_id},
        dataType: "json"
    }).success(function(result){
        if(result.status == "ok"){
            $('.third .title').text(result.data.title);
            $('.third .body').html(result.data.body);
            $('.third').slideDown('fast'); 
        }
    });        
});

});

like image 838
JoeLee Avatar asked Mar 14 '13 09:03

JoeLee


1 Answers

I got the same error on IE11 when using the native function document.body.append.

You can either use document.body.appendChild or insert the polyfill from MDN (npm).

like image 191
Fabian von Ellerts Avatar answered Nov 05 '22 00:11

Fabian von Ellerts