0

Can someone please help? I have some jQuery code which is working perfectly, however there is an element within it which is: "#"+ and I don't understand what it does. Please see below JS.

setTimeout (function() {
     $("#"+toneId2nd).animate({ backgroundColor: 'red'}).animate({ b    ackgroundColor: 'white'}, 4000);
    play_multi_sound('tone-'+toneId2nd);
}, 1000);

Any help greatly appreciated.

Yogesh Sharma
  • 2,017
  • 1
  • 15
  • 33
m acton
  • 11

3 Answers3

0
$('#myElement').animate({ backgroundColor: 'red'}).animate({ backgroundColor: 'white'}, 4000);
play_multi_sound('tone-myElement');

is the same as:

var toneId2nd = 'myElement';
$('#'+toneId2nd).animate({ backgroundColor: 'red'}).animate({ backgroundColor: 'white'}, 4000);
play_multi_sound('tone-'+toneId2nd);

toneId2nd is just a supplied variable.

jQuery uses CSS selectors to grab elements.

I suggest you start here if you need more help with jQuery.

Jamie Barker
  • 8,145
  • 3
  • 29
  • 64
0

it is the Id of the Element $('#ElementId')

toneId2nd is some kind of element ID

Ex: $('#mydiv')

tech-gayan
  • 1,373
  • 1
  • 10
  • 25
0

See the answer on this question : using variables within a jquery selector

And maybe try to do some research before asking? ;)

Community
  • 1
  • 1
Geoff
  • 69
  • 3