views:

52

answers:

4

I'm using this code with jquery

$(".tab").css({'background-color': '#f3f6ed', 'border': '4px solid rgba(0,0,0,0.1)', 'border-bottom': 'none'});

It's to change the style for a tab when I click on it. It works in browsers expect for explorer (stupid microsoft..) I get "invalid argument"

Not sure how I can fix this.

A: 

Whenever you encounter a hyphenated property, like background-color, you have to switch to the camel-case version, i.e. backgroundColor. Edit: As pointed out by Pekka, this was utter nonsense.

Thomas
`.css()` definitely accepts both. http://api.jquery.com/css/
Pekka
Oh, wow, you're absolutely right. I thought, actually, that JS itself wasn't accepting hyphens as part of property names. I must have picked that up wrongly somewhere. :(
Thomas
@Thomas native JS indeed doesn't, but jQuery translates it internally. This library is going to be the death of us one day, making us fat and lazy because it does *everything* :)
Pekka
@Thomas: You can delete answers...
T.J. Crowder
@TJ: It shall serve as a cautionary tale for those that follow.
Thomas
@Pekka: I was actually surprised, that it doesn't translate `rgba()` into an IE-supported version yet.
Thomas
+2  A: 

I am not 100% sure because rgba isn't supported in IE; a reason why it throws the error.

Sarfraz
+3  A: 

I can't test right now, but my suspicion is the rgba part in

rgba(0,0,0,0.1)

IE doesn't support rgba colour values until version 9.

I'm not sure whether there is a jQuery workaround for this. jQuery.support() doesn't seem to be able to sniff rgba support.

In the worst case, you'll have to test for browsers that support the property.

Update: The modernizr library can test for rgba support.

Pekka
+1  A: 

I'm not sure what kind of error you are getting, but if it is a javascript error, I would simply put the properties in a class and use jquery's .addClass() instead.

I would probably do that anyway...

jeroen
Thanks! That's an excellent alternative!
jet789