Clear input with Jquery with more than one class

-2

My input looks like this:

<input type="text" class="noclear form-control" value="" name="" required>

Jquery:

form.find('input[class!="noclear"]').val('');

If I leave the input, just with (class="noclear") works right! But I need to leave this other class (form-control) because it is the formatting of the input.

By logic, it is only to clean the input, where it does not have the class (noclear).

    
asked by anonymous 07.11.2018 / 10:55

2 answers

1

If you want to select all inputs that do does not contain the noclear class, just use the jQuery :not() or the jQuery.not() method.

let $inputs = $('input:not(.noclear)');
// ou
let $inputs = $('input').not('.noclear');

Example:

$('#clear-button').on('click', function() {
    $('input').not('.noclear').val('');
});
.form-control {
    display: block;
    margin: 5px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><inputclass="form-control noclear" value="noclear">
<input class="form-control" value="Input 2">
<input class="form-control" value="Input 3">
<input class="form-control" value="Input 4">

<button id="clear-button">Clear</button>
    
07.11.2018 / 13:32
0

$(document).ready(function(e) {
    $('.meubotaolimpa').click(function(e) {
        $('input[type="text"],input[type="password"]').not('.noclear').each(function() {
                $(this).val('');
        });
    });
});

.meubotaolimpa is the button class (serves only as ex)

edited

    
07.11.2018 / 11:02