Find element to remove via jQuery

1

I have a routine in JS which is as follows:

$('body').on('click', 'a.remover', function(e) {
    e.preventDefault();
    $(this).closest('.info').html("<p>Escolha ao lado</p>").parent().find('input[type=hidden]').val();
});

I would like that when I click on the .remover I would look for the nearest .info div, replace its content with the above, and also clear the value of two input hiddens contained in the .info parent ...

But it did not. It did not return any syntax errors, but did not execute the function.

HTML Structure (Debugger Print, since elements are added dynamically):

How can I proceed?

    
asked by anonymous 04.10.2017 / 22:59

1 answer

1

Your code is almost correct, just missing two quotes within .val() to clear the inputs (I'll leave the inputs visible in the sandbox to see the effect):

$('body').on('click', 'a.remover', function(e) {
    e.preventDefault();
    $(this).closest('.info').html("<p>Escolha ao lado</p>").parent().find('input[type=hidden]').val('');
});

$('body').on('click', 'a.remover', function(e) {
    e.preventDefault();
    $(this).closest('.info').html("<p>Escolha ao lado</p>").parent().find('input[type=text]').val('');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divclass="carrinhoPacoteSigame">
    <div class="info">
        <table class="table">
            <tr>
                <td>
                    <a href="#" class="remover">Remover Item</a>
                </td>
            </tr>
        </table>
    </div>
        <input type="text" name="hdProduto03" value="19" />
        <input type="text" name="hdValor03" value="30" />
</div>
    
05.10.2017 / 00:25