jQuery to check the row count of a table


To get the row count of the table, in jQuery, all you need to do is use any of the following approaches:

$(“#mytable tr”).length

$(“#mytable tr”).size() //But the size method calls the length property internally

One thing to be noted here is that the indexing is 1-based and not 0-based. For ex.:

<html>
<head>
<script src=”jquery-1.3.2.min.js” type=”text/javascript” language=”javascript”></script>
<script type=”text/javascript” language=”javascript”>
$(document).ready(function(){
alert($(“#x tr”).length);
});

</script>
</head>
<body>
<table id=”x”>
<tr><td>1</td></tr>
<tr><td>2</td></tr>
<tr><td>3</td></tr>
<tr><td>4</td></tr>
<tr><td>5</td></tr>
<tr><td>6</td></tr>
<tr><td>7</td></tr>
<tr><td>8</td></tr>
</table>
</body>
</html>

Running the above html will give ‘8’ as the result and not 7.
//
//

FileUpload width property not working


This issue normally comes in Firefox. In IE, setting the css width will take care of the width of the file upload control. In Firefox, you need to use the size property to set the width of the fileupload, as Firefox rendering engine does not set the width on the width property of the control. The solution would look like:

<asp:FileUpload ID=”fuCtgMem” runat=”server” CssClass=”file” size=”31″ /> 

Size is not a pixel value. Hence you have keep checking the proper value for this, in FF. This is the case with the html fileupload control also. Just set the size property and voila! It works in FF.