I’m trying to select all the input fields inside of the element #manage-company
that do not have either the class .partner
nor .representative-input
, and then manipulate their classes. I tried to accomplish this with the line below, but I think my selection syntax is incorrect.
$('#manage-company input :not(.representative-input, .partner)').removeClass('form-control').addClass('form-control-plaintext');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<form id="manage-company">
<input type="text" class="form-control" id="manage-company-name">
<input type="text" class="form-control" id="manage-company-stateRegistration">
<div id="manage-company-representativesList">
<input type="text" class="form-control representative-input">
<input type="email" class="form-control representative-input">
</div>
<div id="manage-company-partnersList">
<input type="text" class="form-control partner">
</div>
</form>
2
Answers
Just remove the space between the
input
and the:not
, like so:input :not
indicates that selects the descendants of the input element by excluding those elements that match the condition in:not()
.That’s the reason why your code is failing.
Remove the space and then it will work fine. (which will indicate that selects those elements which match the condition)
Working snippet:
Note:
added CSS to show you that now code is working
Added
<br>
to just separate elements for better understandability