gtilflm gtilflm - 4 months ago 7
Javascript Question

jQuery Selector (children, eq, and innerhtml)

I want to select the 5th element of the HTML block below which is this table:

<table border="0" style="width: 577px; height: 224px;">
and then alert the
innerhtml
to make sure I'm selecting the right thing.

My jQuery code:
alert($('#content-text').children().eq(5).innerhtml);


HTML block...

<div id="content-text">
<p><span style="font-size: large;"><span style="font-family: comic sans ms,sans-serif;">Title</span></span></p>
<p>&nbsp;</p>
<p><span style="font-size: large;"><span style="font-family: comic sans ms,sans-serif;">Directions</span></span></p>
<table border="0" style="width: 577px; height: 207px;">
<tbody>
<tr>
<td valign="middle">link 1</td>
<td valign="middle">link 2</td>
</tr>
</tbody>
</table>
<table border="0" style="width: 577px; height: 224px;">
<tbody>
<tr>
<td style="text-align: center;"><span style="font-size: medium;">more directions</span>
<p><span style="font-family: tahoma,arial,helvetica,sans-serif;">info</span></p>
</td>
</tr>
<tr>
<td>
Practice probs.
</td>
</tr>
</tbody>
</table>
<table width="610" height="338" cellpadding="0" border="0" style="width: 607px; height: 338px;">
<tbody>
<tr>
<td>
Assignment problems listed out
</td>
<td style="padding-left: 40px;">
Image
</td>
</tr>
<tr>
<td>
info. about correcting problems
</td>
</tr>
</tbody>
</table>




Any ideas why my jquery selector doesn't seem to be working?

Answer

innerHTML is javascript property. Use html() instead like following.

alert($('#content-text').children().eq(4).html());

N.B: not eq(5), eq(4) will select <table border="0" style="width: 577px; height: 224px;">