javascript the OO way - permission denied error on IE
I am trying some javascript like below:
var obj = {
resetCss: function(){
$("#canvas > div").click{function(){
val = $(this).attr("id"); //I get the expected value
obj.setCss(val);
});
},
setCss: function(inp){
alert (inp);
},
getCss: function(){
}
};
Mark up:
<div id="canvas">
<div id="can1">Can开发者_Python百科vas 1</div>
<div id="can2">Canvas 2</div>
<div id="can3">Canvas 3</div>
<div id="can4">Canvas 4</div>
<div id="can5">Canvas 5</div>
</div>
This one works well on FF, Chrome, Safari etc. Only on IE browsers when the script hits "obj.setCss(val);" I get an error "permission denied" and the script execution terminates. Can someone help me with this please?
Thanks, L
You have a { rather than ( in the resetCss function. See below. This is probably being ignored in the other browsers but not IE
var obj = {
resetCss: function(){
$("#id").click(function(){ // <---- Note the ( rather than {
val = $(this).val(); //I get the expected value
obj.setCss(val);
});
},
setCss: function(inp){
//some code here
alert (inp);
},
getCss: function(){
}
};
var obj = {
resetCss: function(){
$("#canvas > div").click{function(){ //I think your code wrong here
val = $(this).attr("id"); //I get the expected value
obj.setCss(val);
});
},
setCss: function(inp){
alert (inp);
},
getCss: function(){
}
};
It should change to
var obj = {
resetCss: function(){
$("#canvas > div").click(function(){ //Change { to (
val = $(this).attr("id"); //I get the expected value
obj.setCss(val);
});
},
setCss: function(inp){
alert (inp);
},
getCss: function(){
}
};
精彩评论