jquery .children() returning wrong size

Posted by i need help on Stack Overflow See other posts from Stack Overflow or by i need help
Published on 2011-02-10T07:13:05Z Indexed on 2011/02/10 7:25 UTC
Read the original article Hit count: 150

Filed under:
|
|
|

Hi guys, I just found the children size not consistent.

Below attach full code with alert, for easy reference.

Is the way I get the data wrong?

<body>
<table width="100" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="30" valign="top"><strong>Header Title</strong></td>
      </tr>

      <tr>
          <td height="32" valign="top">Date : <strong>01/01/2010 </strong> <br><div><b></b></div><span></span></td>
      </tr>
</table>
</body>

$("td").each(function() {
    alert($(this).children().size());   
});

//first td showing 1 direct children- <strong>
//second td showing 4 direct children- <strong> <br> <div> <span>

-----

$("tr").each(function() {
    alert($(this).children().size());   
});

//first tr showing 1 direct children - <td>
//second tr showing 1 direct children - <td>

-----

$("table").each(function() {
    alert($(this).children().size());   
});

// ERROR
// this table showing 1 direct children only.... something WRONG.
// I thought there are 2 <tr> inside this table?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about size