javascript - "SCRIPT5002 function expected" error in IE - Stack Overflow

i am facing an issue and getting error like "SCRIPT5002 function expected" in internet explo

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??

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??

Share Improve this question asked Feb 5, 2013 at 8:41 user1918096user1918096 1531 gold badge3 silver badges10 bronze badges 2
  • 1 what are you trying to acplish? especially with the "appendChild" part? - I don't think the error is in the first line. – OschtärEi Commented Feb 5, 2013 at 8:43
  • How is that script embedded in your page? Is it the only script? – Bergi Commented Feb 5, 2013 at 8:47
Add a ment  | 

2 Answers 2

Reset to default 2

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;

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745615284a4636197.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信