user1918096
user1918096

Reputation: 153

"SCRIPT5002 function expected" error in IE

i am facing an issue and getting error like "SCRIPT5002 function expected" in internet explorer 7-9. this is my code :

 var myDiv = document.getElementById("divId"); //this line gives me "SCRIPT5002 function expected" error.

 myDiv.style.cssText("position:absolute;z-index:999");
myDiv.appendChild(
        JavaScriptCode);

so how to solve this??

Upvotes: 1

Views: 10161

Answers (2)

posit labs
posit labs

Reputation: 9431

I also got this in an attempt to check if a variable was an Element.

"notAnElement" instanceof Element

And it always throws the function expected error.

document.createElement("div") instanceof Element

Successfully evaluates to true

I haven't implemented it yet, but my solution is to use a try/catch block.

Upvotes: 0

Sirko
Sirko

Reputation: 74076

The problem should be in the 2nd line:

myDiv.style.cssText("position:absolute;z-index:999");

cssText is not a function, but a property. So call it like this:

myDiv.style.cssText = "position:absolute;z-index:999";

or (better approach in my opinion, because it is clearer):

myDiv.style.position = 'absolute';
myDiv.style.zIndex = 999;

Upvotes: 2

Related Questions