0

IE doesn't like the sharp symbol in the line below

jQuery(this).css('background-color','#' + jQuery(this).prev().val());

so I'm wondering if there is a different way to write the same without get error in IE?

4
  • 1
    What error do you get? I've used code similar to that (that is, concatenate '#' + variable to get something), and it works perfectly in IE. Might the error just be that $(this).prev().val() is null or empty? Commented Mar 17, 2010 at 15:25
  • Does it work in other browsers? Commented Mar 17, 2010 at 15:34
  • Yeah, looks like IE doesn't like the empty value. Added a check and it works fine now. Thanks! Commented Mar 17, 2010 at 15:37
  • The error was "Invalid property value" and yes it was working fine in other browsers, at least in firefox and chrome. Commented Mar 17, 2010 at 15:39

1 Answer 1

1

I've tested $(this).css('background-color', '#fff000'); in IE and it works fine so I don't think it's the sharp. It's how the color is either being constructed or an issue with quotes. Try:

var newColorTest1 = '#' + jQuery(this).prev().val();
alert(newColorTest1);
jQuery(this).css('background-color', newColorTest1);

What is shown in the alert box?

What is the value of jQuery(this).prev().val(); in your markup?

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the answer. The problem was that the value was empty in some cases and that caused the error. if(jQuery(this).prev().val() != '') solved it.
No problem. Please consider marking as the answer if investigating jQuery(this).prev().val(); assisted in finding the root cause...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.