开发者

array_name.className gives "className is null or not an object" in IE

开发者 https://www.devze.com 2023-02-09 03:40 出处:网络
I am using jQuery Datatables plugin for displaying data. This works perfectly in Mozilla and Chrome b开发者_开发技巧ut in IE, it produces

I am using jQuery Datatables plugin for displaying data. This works perfectly in Mozilla and Chrome b开发者_开发技巧ut in IE, it produces "className is null or not an object" error at the following line of code in jQuery.Datatables.js

Code: if ( nTds[i].className.indexOf(sClass+"1") != -1 ) { for ( j=0, jLen=(nTds.length/iColumns) ; j

I am not sure if the problem pertains to "indexOf" or "className" as IE does not support indexOf

Any help on this issue would be appreciated


The object itself is problematic... naturally the property will as well.

I used:

if(typeof nTds[i] != 'undefined' && typeof nTds[i] !=null && typeof nTds[i] !='null')
{
   // original className check code in here
}


You're getting an element that does not have a className property defined. Do a type check before the indexOf check.

if(typeof nTds[i].className != 'undefined' && nTds[i].className.indexOf(sClass+"1") != -1) { ...

EDIT:

Try this code exactly.

    if(typeof nTds[i].className != 'undefined') {
        if ( nTds[i].className.indexOf(sClass + "1") != -1) { 
            for ( j=0, jLen=(nTds.length/iColumns) ; j<jLen ; j++ ) { 
                nTds[(iColumns*j)+i].className = $.trim( nTds[(iColumns*j)+i].className.replace( sClass+"1", "" ) ); 
            } 
        } else if ( nTds[i].className.indexOf(sClass+"2") != -1 ) { 
            for ( j=0, jLen=(nTds.length/iColumns) ; j<jLen ; j++ ) { 
                nTds[(iColumns*j)+i].className = $.trim( nTds[(iColumns*j)+i].className.replace( sClass+"2", "" ) ); 
            } 
        }
    }


Basically the same as Danial's answer, but it's no need to explictly check for undefined:

if ( nTds[i].className && nTds[i].className.indexOf(sClass+"1") != -1 ) { ...
0

精彩评论

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

关注公众号