Error when trigger click event in IE6/IE7 (jquery)
I have this code:
$("#boxId ul li a:eq(0)").click();
Works ok in IE8 and FF, but I'm getting error in IE6 and IE7.
"Object doesn't support this property or method"
Someone knows why?
Obs:
$("#boxFoto 开发者_开发问答ul li a:eq(0)").size(); // returns '1'
There's no reason for jQuery's click() to fail on IE. I think the click
event is actually triggered, but:
You have set an
onclick
handler on the hyperlink, and it tries to access a property or a method that's undefined under IE, orYou have an
href="javascript:....."
attribute on the hyperlink that has the same problem as above.
I found the error.
My code creates HTML dinamically, using this:
a.setAttribute("onclick","return false");
I changed to
a.onclick = function(){return false;};
And now works!
IE6/IE7 were returning the string "return false" in jquery code, not the function(){return false}. Somewhere in jquery code, I was getting "return false".apply(....., .....), that was the cause of the error Object doesn't support this property or method
.
精彩评论