0

I'm trying to set a css expression for an attribute for an element as follows.

var scrollTopExpr = '$(document).scrollTop()';
var expr = "expression(eval(" + scrollTopExpr + "))";
$(this).css("top", expr);

But i'm getting "Invalid Argument" as an error. Any ideas?

3
  • What browser is this in? CSS expressions are only supported by IE, and in IE8 only when in comptability mode, because they are considered deprecated by Microsoft. Commented Aug 19, 2010 at 10:13
  • I'm trying to do position fixed and i'm trying to support IE6+ FF 2.0+. But IE7 and IE8 is not supporting postion:fixed without a doctype. I'm doing an addon product for a CMS system where i cant give my own doctype. How can i do it then? Commented Aug 20, 2010 at 5:23
  • 1
    It would be helpful if the downvoters spend couple of minutes telling the reason for the downvote. Commented Jan 18, 2012 at 15:14

1 Answer 1

2

Expressions were deprecated and removed in IE8 (unless you're in compatibility mode). They're also performance hogs and you should stay away from them if you can, using JavaScript instead.

You don't need to use eval() inside expression(), and this is what's causing your error. eval() expects a string, but you're passing the result of a variable to it, which is a Number. Take out eval():

"expression(" + scrollTopExpr + ")";

expression() already evaluates the expression you pass to it, so eval() is entirely unnecessary.

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

Comments

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.