If an input element has multiple classes assigned as below(form-control and hide). How can we find it using single class
eg <tr id="10"><td><input class="form-control hide" name="[0].Items" type="number" value="1" /></td></tr>
I've tried the following but it does not work
$('tr#10').find("input[class='hide']").addClass('show').removeClass('hide')
but the following does work
$('tr#10').find("input[class='form-control hide']").addClass('show').removeClass('hide')
But I don't want to use find with multiple classes
$('tr#10 input.hide').toggleClass('show hide');
If you insist on using the attribute selector, it has to be this:
$("tr#10 input[class~='hide']").toggleClass('show hide');
which matches input elements amongst whose classes is an exact match 'hide'.
Simpy refer to the desired classes with a .
$('tr#10').find(".form-control")
or
$('tr#10').find(".hide")
or
$('tr#10').find(".form-control.hide")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.