Reema Reema - 1 month ago 9
jQuery Question

jquery - get input and select elements with id start and ends with

I have found how to get the elements whose id starts with

aName
and ends with
EditMode
as below: jQuery selector for matching at start AND end of ID?

$('[id ^=aName][id $=EditMode]')


I have also found how to get the elements of type input and select as below: jQuery find input type (but also for select)

$('input, select');


How can I combine both these to get all the input and select elements whose ids start with
aName
and end with
EditMode

Answer Source

Use .filter()

Reduce the set of matched elements to those that match the selector or pass the function's test.

$('input, select').filter('[id^=aName][id$=EditMode]')....

OR, Combine selectors

$('input[id^=aName][id$=EditMode], select[id^=aName][id$=EditMode]').....