I'm trying to get the JQuery right to select the text from the following html structure:
<TABLE class=ms-formtable>
<TBODY>
<TR></TR>
<TR></TR>
<TR></TR>
<TR></TR>
<TR></TR>
<TR>
<TD><H3><NOBR>Select this text</NOBR></H3></TD>
<TD></TD>
</TR>
</TBODY>
</TABLE>
simple selector
$('nobr').text();
more explicit selector
$('table.ms-formtable > tbody > tr > td > h3 > nobr').text();
An example to play with
There is a number of ways of doing that. Is this the only table with that class name? My guess is $('table.ms-formtable nobr').text()
, but it depends on the rest of the HTML, because this could select more than one element's text.
Could you perhaps use an ID to specify your H3 tag and therefore be able to select it using something like $('#textToSelect').text()
.
That way you could be absolutely sure which text you were targeting on the page.