Saleh Ahmad Oyon Saleh Ahmad Oyon - 5 months ago 11
jQuery Question

I want to use the text of a span which has attribute 'hidden'

I want to use the text inside of a span. this tag contains html5

hidden
attribute.

<tr>
<td>First</td>
<td>Second</td>
<td>Third</td>
<td>
<button class="editBtn" title="Edit">Edit</button>
</td>
<span hidden>1</span>
</tr>


How can i fetch the text of the span using jquery ? I have tried but it gives me the wrong value. Every time it gives "2".

var value = $('.editBtn').closest('tr').children()[4].textContent;


How can i solve this problem ?

Answer

Put span into td and then try:

<table>
<tr>
    <td>First</td>
    <td>Second</td>
    <td>Third</td>
    <td>
        <button class="editBtn" title="Edit">Edit</button>
    </td>
    <td>
    <span hidden>1</span>
    </td>
</tr>
</table>

jQuery:

alert($('.editBtn').closest('tr').find('span').text());