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
2 Answers
Reset to default 2The 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条)