Reputation: 32808
I have:
var row = 22;
How can I set it so that all my input and select elements that have IDs where XXX can be any combination of characters are disabled:
modal_XXX_22
Upvotes: 1
Views: 67
Reputation: 144689
You can try Multiple Attribute
selector:
$('*[id^="modal_"][id$="_'+row+'"]').prop('disabled', true)
// ^- ^-- ^--- attribute ends with selector
// | |
// | --- attribute starts with selector
// ---- all selector
Upvotes: 1
Reputation: 7470
$('input[id^="modal_"][id$="_'+N+'"],select[id^="modal_"][id$="_'+N+'"]')
.attr('disabled','disabled');
Upvotes: 0
Reputation: 42450
You can iterate over all children and check if the id contains the string you want. Like this:
$(document).ready(function(){
$('ul').children().each(function(){
var id = $(this).attr('id');
if (typeof(id) !== 'undefined') {
if (id.indexOf('22') != -1) {
$(this).css('color','red');
}
}
});
});
If you want it to run on your entire file, you can change it to
$('body').children()...
Upvotes: 0
Reputation: 254926
That is how you would select them:
$('[id^="modal_"][id$="_' + row + '"]').
Upvotes: 2
Reputation: 22241
Try:
$(':input[id^="modal_"][id*="_'+ row +'_"]')
Though a better HTML setup would be single element wrapping inputs.
Upvotes: 0