-2

I have the following code, I want to find the closest tr element but it didn't work.(returns undefined) But I can get closest 'ul', 'li' without problem . Any help is greatly appreciated. Thanks

I have added the actual html code below

HTML

<tr>

<td>

.......want to find something here

</td>
<td class="some class name">
        <div align="right" class="number">
            <div>
                <a class="hover" href="#"><img src="preview.jpg"       width="24px" height="24px"></a>
            </div>
        </div>
    </td>

</tr>

1 Answers1

3

Well. As I know of it TR tag should be used in TABLE tag. table tab should looks like below.

<table>
   <tbody>
      <tr>
         <td>

........

         </td>
     </tr>
   </tbody>
</table>

So you should add TABLE, TBODY tags before adding TR and add TD before adding your own UL.

Don't forget to close BODY tag and add HTML tag in the beginning of HTML document.

It should work. I've tested on my local.

updated html.

<body class="ancestors">body (great-great-grandparent)
    <input type="button" value="test" />
    <div style="width:500px;">div (great-grandparent)
        <table>
            <tbody>
                <tr>
                    <td>
                        <ul>ul (grandparent) 
                            <li>li (direct parent)
                                <span class='extralink'>span</span>
                            </li>
                        </ul> 
                    </td> 
                </tr>
            </tbody>
        </table>
    </div>
</body>
Wang YinXing
  • 136
  • 6