-1

While assigning a value for a variable, the variable is taking wrong value. The code is

var txtColor = $(".menu-item").css("background-color");

Where $(".menu-item").css("background-color"); represents pink color. But txtColor is taking as "transparent".

I'm seeing this issue only in IE-8.

Can anyone help me in fixing this issue.

Thanks in advance.

ketan
  • 19,129
  • 42
  • 60
  • 98
Niveditha
  • 107
  • 1
  • 7
  • 1
    Are you, by chance, using jQuery v2.x? That is not compatible with IE8. You would need v1.x for IE8. – jfriend00 Apr 16 '15 at 05:13
  • On a side note, IE8 is pretty much [on the way out](http://exisweb.net/ie8-will-not-die-quietly) - with so few users using it, is it even worth trying to support it at this point? Unless you're building something that must run on some legacy corporate system, I'd argue against supporting it at all. – Krease Apr 16 '15 at 05:20
  • There must be something else going on here because the code you show works just fine in IE8 when used with jQuery 1.11.2. You will have to show more of what you're doing for anyone else to know how to help. Try this [simple web page](https://dl.dropboxusercontent.com/u/7909102/test3.html) in IE8 and you will see it works. It does not return "pink" in other browsers (I see `rgb(...)`), but does work in IE8. – jfriend00 Apr 16 '15 at 05:28
  • To the OP, where are you? People have asked you clarifying questions and you're not around. That's now how StackOverflow works. It is not like a forum where you post and come back the next day. You should hang around for 15-30 mins after you post to see if people have questions you need to clarify. If not your question may be downvoted or closed before you come back. Plus, the most people will see your question in the first 30 minutes so if it's not clear then, you will miss the majority of your opportunity for an answer. – jfriend00 Apr 16 '15 at 05:45

1 Answers1

0

Question, is your CSS set up like this?

background: pink;

If so, try using $('.menu-item').css("background"); instead.

Old versions of IE will not properly cascade group definitions (like background) to the other settings. In modern browsers, defining background as "pink" will also set the background-color to "pink".

Josh
  • 3,258
  • 2
  • 19
  • 31