0

Have the following code:

var i = 1;
while (i<22){ 
  $('[id^="trloc"]').show();
  i++;
}

I need to add the value of i to the id - something like this:

$('[id^="trloc" + i]').show();

But I cannot seem to get it to work - any suggestions?

2 Answers 2

2
$('[id^="trloc'+ i  +'"').show();

simply

$('#trloc' + i).show();

if you don't have any other part after i like: trloc1_a,troloc2_b etc then second solution will work just fine.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you - damned apostrophes and semi colons!
1

Try this

 $('#trloc' + i).show();

If you search by id, use '#'. It is both easier and faster.

1 Comment

Thanks Sanja, appreaciated.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.