Francisco G Francisco G - 4 months ago 13
Javascript Question

Select text inside <b></b> tags

I think is a simple question, but I am having some issues with that.

I need to get the value between

<b></b>

It is inside of a tbody, tr, and td.

Here is the HTML

<table class="table table-bordered table-striped">
<tbody class="connectedSortable" id="table-draggable-@i">
<tr>
<td align="center">
<b>@year.Year</b>
</td>
</tr>
</tbody>
</table>


My jQuery is the following:

$("#table-draggable-2 > tr:first > td > b")


And as a result I get:

[<b>​2017​</b>​]


But I just need the 2017 value. What am I missing?

Answer

Almost there. Try this:

var value = $("#table-draggable-2 > tr:first > td > b").text();
Comments