javascript – Get sibling id of the item that triggered the event


I have a table and inside das <td> I have two input:

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

I need when I change the value of the input number it returns the value of the CdProduto input .

Remembering that this link will be repeated according to the quantity of product.

    $(":input").bind('keyup mouseup', function () {
<script src=""></script>
<table class="table">
                                <th colspan="2">Produto</th>
                                <th>Valor unitário</th>
                                <th colspan="2">Sub Total</th>
                                            <a href="#">
                                                <img alt="White Blouse Armani">
                                        <td><a href="/produtos/2">Pao</a>
                                            <input id="CdProduto" value="2" hidden>
                                            <input type="number" value="1" class="form-control">
                                        <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>
                                <th colspan="5">Total</th>
                                <th colspan="2">R$ 1,00</th>

How am I going to do this?


Use siblings :

$(":input").bind('keyup mouseup', function () {

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" />
Scroll to Top