Attaching event lisener with arguments.
-
Hi All! I've following table in my web page:
<table id="tblTest"> <tr> <td> dfdf</td> <td> dfdf</td> </tr> <tr> <td> sfds</td> <td> fdsf</td> </tr> </table>
i've put following javascript code in script tag:window.onload = function() { var Trs = document.getElementById('tblTest').children[0].children; for(var n=0; n<Trs.length; ++n) if(document.addEventListener) Trs[n].addEventListener('click', function(){ Information(Trs[n], Trs[n].children.length); }, false ); else if(document.attachEvent) Trs[n].attachEvent('onclick', function(){ Information(Trs[n], Trs[n].children.length); } ); }
function Information(tr, trCount) { alert(tr.nodeName); alert(trCount); }
but on clicking on any row following javascript error raised: Microsoft jScript runtime error: 'Trs[...].children' is null or not an object can any body tell me where i have made mistake?