Ferdian Ferdian - 3 months ago 18
Javascript Question

How To Add More Class after This condition in Javascript?

The origin script, work fine if I only add one class:

function check_btn_charge() {
if (parseInt(jQuery(".total-change-price").text()) >= 0) {
jQuery(".btn-action-save-charge"+" "+"btn-danger").prop("disabled", true);
}
else {
jQuery(".btn-action-save-charge"+" "+"btn-danger").prop("disabled", false);
}
}


And I've tried to add more class in this condition using plus (+) sign and space character as separate class, like in the script below but not working :

function check_btn_charge() {
if (parseInt(jQuery(".total-change-price").text()) >= 0) {
jQuery(".btn-action-save-charge").prop("disabled", true);
}
else {
jQuery(".btn-action-save-charge").prop("disabled", false);
}
}


what should I do to this script so that working well?

Answer

If you want to select an element with both classes 'myClass1' and 'myClass2':

jQuery('.myClass1.myClass2')

If you want to select elements with one of the classes 'myClass1' or 'myClass2':

jQuery('.myClass1, .myClass2')

More than two classes follows the same rules.

More info