简体   繁体   中英

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, or

  • You 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM