Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have the following HTML table

HTML
<table width="100%" id="tbl1" cellpadding="4">
	<tr>
		 <td bgcolor="#F2F2F2" class="FieldNames">
			Table Data
		</td>     
	</tr>
	<tr style="display: inline-block;">
		 <td bgcolor="#F2F2F2" class="FieldNames">
			Table Data
		</td>     
	</tr>
	<tr id="tr1">
		<td bgcolor="#F2F2F2" class="FieldNames">
			Table Data
		</td>                                                        
	</tr>
</table>


if I am accessing this table rows in JavaScript it only shows 2.

JavaScript
var tbl1= document.getElementById('tbl1');
alert(tbl1.rows.length);//return only 2


If i remove the 'style="display: inline-block;"' from middle row, it is working fine and returning 3.

Is there any DOM processing related changes in IE-11?


Just put following HTML code in a HTML file. Run and click on the button. Issue will be visible

HTML
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Manish Test</title>
   <script type="text/javascript" lang="javascript">
        function showcount()
        {
            var tbl1= document.getElementById('tbl1');
            alert(tbl1.rows.length);//return only 2
            return false;
        }
    </script>
</head>
<body>     
    <table width="100%" id="tbl1" cellpadding="4">
	<tr>
		 <td bgcolor="#F2F2F2" class="FieldNames">
			Table Data
		</td>     
	</tr>
	<tr style="display: inline-block;">
		 <td bgcolor="#F2F2F2" class="FieldNames">
			Table Data
		</td>     
	</tr>
	<tr id="tr1">
		<td bgcolor="#F2F2F2" class="FieldNames">
			Table Data
		</td>                                                        
	</tr>
</table>
    <input type="button" id="btnTest" value="Test" onClick="showcount();" />
</body>
</html>



My IE-11 exact version is 11.0.9600.16428
Posted
Updated 26-Feb-14 2:41am
v2
Comments
Sergey Alexandrovich Kryukov 24-Feb-14 12:06pm    
What do you want to achieve with such pretty strange styling? Especially when you have only one "td" per row, which would pretty defeats the purpose of table...
—SA
Manish Ray 24-Feb-14 12:28pm    
I have just imitated the actual problem statement. In actual table there are 4 tds per tr.
Sergey Alexandrovich Kryukov 24-Feb-14 12:40pm    
Could you then make your sample more realistic and point out what do you want to achieve with this inline-block?
—SA
Kornfeld Eliyahu Peter 24-Feb-14 14:39pm    
I just run it in IE11 and got 3!!!
Maybe you missed some code?
Manish Ray 26-Feb-14 9:13am    
Can you recheck with complete HTML which I have added later in question?

1 solution

A TR displays a table-row by default, and apparently changing that to inline-block ensures that IE11 no longer considers it to be a row. No idea why it does that, but that's not important. You need to deal with the fact that it does and work around it (welcome to the wonderful world of web development). I suggest using jQuery or some other library. With jQuery you can simply do this:
JavaScript
var rowCount = jQuery('#tbl1 tr').length;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900