jquery on click sibling selection

Posted by Deviland on Stack Overflow See other posts from Stack Overflow or by Deviland
Published on 2012-11-02T10:54:34Z Indexed on 2012/11/02 11:00 UTC
Read the original article Hit count: 228

Filed under:
|
|

I generate a Table from a database to look like this

<table id="items">
<thead>
    <tr>
        <th>Details</th>
        <th>Goldmine ID</th>
        <th>&nbsp;</th>
    </tr>
</thead>
<tbody>
    <tr>
        <td class="evenrow">This is a test Description generated through UNIT Tests for the category description</td>
        <td class="evenrow"><input type="text" value="" id="106" class="gminput"></td>
        <td class="butCell evenrow"><button class="saveButton updateitem">Update</button></td>
    </tr>
    <tr>
        <td class="oddrow">This is a test Description generated through UNIT Tests for the category description</td>
        <td class="oddrow"><input type="text" value="" id="107" class="gminput"></td>
        <td class="butCell oddrow"><button class="saveButton updateitem">Update</button></td>
    </tr>
    <tr>
        <td class="evenrow">This is a test Description generated through UNIT Tests for the category description</td>
        <td class="evenrow"><input type="text" value="" id="108" class="gminput"></td>
        <td class="butCell oddrow"><button class="saveButton updateitem">Update</button></td>
    </tr>
</tbody>
</table>

I am trying to get the input box value and id returned by the relevant row's button click

so far I have tried this but failed

$('body').on('click', '.updateitem', function(event) {
    event.preventDefault();
    $(this).parent().siblings().forEach(function(index) {
        alert(($(this).val()));
    });
    var par = sib.parent('td');
    par.addClass('redBorder');
});

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about html