2

I used this code to get to the text inside the first td element in each tr row:

 $('tr').each(function () {
        var tds = $(this).find('td'),
        text = tds.filter('[id^="refKey_"]').text(),

The HTML was:

<tr id="row_1">
  <td id="tempRowKey_1" >1.0.0</td>

However I have now changed my code and I have this HTML:

<tr id="row_1">
  <td id="tempRowKey_1" >
    <input type="text" size="10" value="1.0.0" class="updatable" id="TempRowKey_1">
  </td>

Can someone tell me how I can get the values such as "1.0.0" now that they are inside an input. Can I this time use the id of "TempRowKey_xxxx" ?

Update: I tried the following and also tried the answer given but neither work:

    var tds = $(this).find('input'),
    text = tds.filter('[id^="TempRowKey_"]').val(),

can anyone see anything wrong?

1 Answer 1

7

you should use val() for input elements, try this:

$('tr').each(function() {
    var val = $(this).find('input').val();
})
Sign up to request clarification or add additional context in comments.

1 Comment

I tried this but I cannot get it to work. Can you fit this into using the filter and also getting the id. I have more than one input on each row.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.