Reputation: 10744
I have this jquery code:
$('#csv_button').attr('disabled', 'disabled').addClass("disabled");
$('#excel_button').attr('disabled', 'disabled').addClass("disabled");
$('#delete_button').attr('disabled', 'disabled').addClass("disabled");
Is it possible simplify this code to one line of code?
Upvotes: 0
Views: 79
Reputation: 21233
Or you can do:
$("[id$='button']").prop('disabled', true).addClass("disabled");
This will return all elements with id ending with 'button'.
More information on jquery selectors can be found here.
Upvotes: 0
Reputation: 43077
You can separate multiple selectors with commas:
$('#csv_button,#excel_button,#delete_button').prop('disabled', true).addClass("disabled");
Or you could apply the same class to all 3 elements and use a class selector:
$('.disabled-button').prop('disabled', true).addClass("disabled");
Upvotes: 6
Reputation: 14419
$('#csv_button,#excel_button,#delete_button').attr('disabled','disabled').addClass("disabled");
Upvotes: 0