NLV
NLV

Reputation: 21641

Setting CSS Expression using $.css() in JQuery

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?

Upvotes: 0

Views: 1546

Answers (1)

Andy E
Andy E

Reputation: 344605

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.

Upvotes: 2

Related Questions