0

a problem here. I'm trying to remove a textArea value on 2 different buttons click (to be clear, when the button X and NO are clicked)

The problem is that when I'm selecting like this:

    $('#reject_loan_modal-no', '#close-loan-rejection').on('click', function(e) {
    e.preventDefault();
    $('#loan-rejection-modal').modal('hide');
    $('#clientservice-loan_approval_comment').val('');
});

It doesn't work at all. But when I'm seperating these two into a different .on('click') events, it works fine.

But I don't want to duplicate the code, so looking for a proper way to do it..

Thanks for any help

HELPME
  • 714
  • 14
  • 35
  • 1
    Possible duplicate of [Selecting multiple classes with jQuery](https://stackoverflow.com/questions/488305/selecting-multiple-classes-with-jquery) - no need to close the quotes - `$('#reject_loan_modal-no, #close-loan-rejection')` – Pete Jan 15 '18 at 14:53

2 Answers2

3

Selectors are supposed to be placed within the same string:

$('#reject_loan_modal-no, #close-loan-rejection').on('click', function(e) {
    e.preventDefault();
    $('#loan-rejection-modal').modal('hide');
    $('#clientservice-loan_approval_comment').val('');
});
GermanC
  • 279
  • 2
  • 8
2

You can apply a class to both of these buttons and use that class as a jQuery selector.

Johannes
  • 64,305
  • 18
  • 73
  • 130