开发者

jQuery append() issue in IE

开发者 https://www.devze.com 2023-01-20 09:26 出处:网络
I have the following script which I am running.It loops through each table in the page and appends \"Table n [Table Title]\" below each table.

I have the following script which I am running. It loops through each table in the page and appends "Table n [Table Title]" below each table.

This script works fine in开发者_如何学JAVA Chrome, Mozilla but not IE 6 or 7. No errors are captured. Can anyone help with explaining if I have missed something here in my script or is this a bug in jQuery? If this is a jQuery issue, can anyone suggest a workaround?

        $('table').each(function(index,value){
        var obj = $(this).attr('title');
        var i = index;
        var txt = '<span class="toc-caption">Table '+(i+1)+' '+obj+'</span>';
        $(this).append(txt);
    });

Thanks in advance


Your appending a span to a table which of course is not correct and quite rightly ie is blowing up.

Try .after or you could use the caption tag of the table

 $('table').each(function(index,value){
    var obj = $(this).attr('title');
    var i = index;
    var txt = '<span class="toc-caption">Table '+(i+1)+' '+obj+'</span>';
    $(this).after(txt);
0

精彩评论

暂无评论...
验证码 换一张
取 消