In my searches I have found plenty of questions/answers on how to find elements that end with a specific string. I've done a quick search and have not found anything specific about how to find elements that end with a variable. I did find this question/answer about how to use Javascript variables in jQuery selectors in general but I cannot get it to work and I wonder if it's because I'm trying to work against a set of elements I've already filtered down to.
Here are some id's of the elements I've already filtered:
["ms-goal-select-0", "ms-goal-input-0", "ms-goal-select-1", "ms-goal-input-1", "ms-goal-select-2", "ms-goal-input-2"]
And here is the (beginning of) the for loop I'd like to use to find and work with the select and input elements:
for (var x=0;;x++) { //will break when element(s) not found
selectEl = filteredElements.find('[id$="select-' + x + '"]');
inputEl = filteredElements.find('[id$="input-' + x + '"]');
....
But the above does not find the elements starting from the first iteration when x==0
. What am I doing wrong?