Reputation: 187
Hi i have an application which was supressed with compatibility mode IE-5. In that application they are using .all API in javascript to fetch an particular element from DOM It was working fine. but in Windows 10 Machine when i use the same application in IE-11 browser it didn't support .all . So kindly let me know the alternative option for .all in javascript or jquery.
Examples:1
JSP:
<Table id="testtable">
<tr> </tr>
<tr> </tr>
<tr id="testrow">
<td> <FONT size=1 face="Verdana, Arial">
<INPUT class=list maxLength=12 size=3 name=prime1>
</FONT> Test Data1
</td>
<td> <FONT size=1 face="Verdana, Arial">
<INPUT class=list maxLength=12 size=3 name=prime2>
</FONT> Test Data2
</td>
<td> <FONT size=1 face="Verdana, Arial">
<INPUT class=list maxLength=12 size=3 name=prime3>
</FONT> Test Data3
</td>
<td> <FONT size=1 face="Verdana, Arial">
<INPUT class=list maxLength=12 size=3 name=prime4>
</FONT> Test Data4
</td>
<td> <FONT size=1 face="Verdana, Arial">
<INPUT class=list maxLength=12 size=3 name=prime5>
</FONT> Test Data5
</td>
<td> <FONT size=1 face="Verdana, Arial">
<INPUT class=list maxLength=12 size=3 name=prime6>
</FONT> Test Data6
</td>
</tr>
</Table>
Js:
function tablesample (tableId,rowId)
{
var tab = document.getElementById(tableId);
var row = tab.rows(rowId);
var tdc ;
var count ;
var colcount = row.cells.length;
for(var i=2;i<colcount;i++)
{
tdc = row.cells[i];
count = tdc.all.length;
}
}
}
when the above js method Is triggered while reaching the line tdc.all.length; I got an issue "Unable to get property "length" of undefined or null ". It should give the length as 2 but it didn't. Kindly help me to resolve this issue.
Upvotes: 0
Views: 1103
Reputation: 846
Try this:
var tab = document.getElementById('testtable');
var row = tab.getElementsByTagName('tr')
var number_of_children = row.testrow.children.length;
Upvotes: 0
Reputation: 30473
Use .children
-- it's supported by all browsers, while .all
is specific to old versions of IE.
MSDN says it's not supported starting with Internet Explorer 11.
As it's not supported tdc.all
returns undefined
. Then you do undefined.length
which gives the error Unable to get property "length" of undefined or null
.
Upvotes: 1