views:

34

answers:

1

Hello all

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?

+1  A: 

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.

Andy E