Get sibling id of the item that effected event

Asked

Viewed 127 times

3

I have a table and within the <td> I have two input:

<input id="CdProduto" value="15" hidden>
<input type="number" value="2" class="form-control">

I need when to change the value of input number he returns me the value of input CdProduto.

Remembering that this link will repeat itself according to the quantity of product.

    $(":input").bind('keyup mouseup', function () {
        alert("changed");
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table class="table">
                            <thead>
                            <tr>
                                <th colspan="2">Produto</th>
                                <th>Quantidade</th>
                                <th>Valor unitário</th>
                                <th>Desconto</th>
                                <th colspan="2">Sub Total</th>
                            </tr>
                            </thead>
                            <tbody>
                                    <tr>
                                        <td>
                                            <a href="#">
                                                <img alt="White Blouse Armani">
                                            </a>
                                        </td>
                                        <td><a href="/produtos/2">Pao</a>
                                        </td>
                                        <td>
                                            <input id="CdProduto" value="2" hidden>
                                            <input type="number" value="1" class="form-control">
                                        </td>
                                        <td>R$ 1,00</td>
                                        <td>R$ 0,00</td>
                                        <td>R$ 1,00</td>
                                        <td><a href="#"><i class="fa fa-trash-o"></i></a>
                                        </td>
                                    </tr>
                            </tbody>
                            <tfoot>
                            <tr>
                                <th colspan="5">Total</th>
                                <th colspan="2">R$ 1,00</th>
                            </tr>
                            </tfoot>
                        </table>

How am I gonna do this ?

1 answer

2


Use siblings:

$(":input").bind('keyup mouseup', function () {
    $(this).siblings(':hidden').val();
})

Another detail is that you have to use type=hidden instead of hidden.

<input id="CdProduto" value="15" type="hidden" />
<input type="number" value="2" class="form-control" />

Browser other questions tagged

You are not signed in. Login or sign up in order to post.