-2

This may be a very simple question in syntax but I've been googling and still can't find the answer.

I'm trying to set focus to the first SELECT element which has a specific string but the string is held in a dynamic variable. What would be the correct syntax? I thought the below would be correct but it doesn't seem to work.

$('SELECT[id*=" + qID"]').focus();
user3191726
  • 429
  • 1
  • 4
  • 9
  • possible duplicate of [How to use javascript variables in jquery selectors](http://stackoverflow.com/questions/5891840/how-to-use-javascript-variables-in-jquery-selectors) – Colin Brock Mar 01 '15 at 17:28

1 Answers1

3

Try this

$('select[id*="' + qID + '"]').focus();
Oleksandr T.
  • 76,493
  • 17
  • 173
  • 144