Reputation: 29
I have a problem with this selector, I don't know why it isn't working, it's driving me nuts.
I have this:
variable = "#2";
$('"'+variable+'"').css("background-color", "red");
https://i.sstatic.net/HgqYJ.png
Can you help me?
Thank you in advance!
Upvotes: 1
Views: 42
Reputation: 87203
You don't need concatenation
in this case. You can use variable
directly as selector.
$(variable).css("background-color", "red");
jQuery
as selector
javascript
has it as reserved keyword.Upvotes: 1