Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  7] [ 6]  / answers: 1 / hits: 19829  / 13 Years ago, wed, november 9, 2011, 12:00:00

I am trying to set a background color for an ID + Variable but I can't figure it out. There must be something really small that I am not aware of.



Here is what I have:



var abc = $dialog.data( url );
alert(abc)


This Alerts: item1



var cde = '#' + abc
alert(cde)


This Alerts: #item1



So far so good. Now, I'm trying to change the background for that ID.
So:



This works:



$(body).css('background-color', 'black');


This doesn't:



cde.css('background-color', 'black');
$(cde).css('background-color', 'black');
$(# + abc).css('background-color', 'black');


All are in the same function.



What I'm I doing wrong?



Thanks a lot


More From » jquery

 Answers
7

The only reason I see that your code is not working is because the value that you pass to jQuery (namely cde or # + abc) is not of type String.



You can do some test for that :



var test = #item1;
alert(test === cde);
alert(typeof(cde));


If the type is not string, then you could simply do :



$(cde.toString()).css('background-color', 'black');

[#89224] Tuesday, November 8, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cierra

Total Points: 504
Total Questions: 108
Total Answers: 109

Location: Northern Mariana Islands
Member since Fri, Jan 15, 2021
3 Years ago
;