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 ) { ...
精彩评论