jQuery - trigger('click') not working in IE - Object does not support this property or method

荒凉一梦 提交于 2019-12-12 14:31:07

问题


I have an images with a fading overlay div on hover which displays a text link within.

When the link is clicked it opens a shadowbox with content. I want the whole overlay div to be clickable so I used :

$("div.overlay").each(function(){                
         $(this).click(function(){
             $('a#overlink').trigger('click'); // id of shadowbox link

             return false;

             });


       });

It works fine in FF, Safari & Chrome but IE shows a 'Object doesn't support this property or method' error.

Is there another way of doing this or another method to use?


回答1:


Which version of ie are you using ? I remember that some version of IE don't support clicking objects other than links or buttons :(

perhaps try with a mousedown event as a workaround




回答2:


I wouldn't recommend this approach. Why can't you call the function which handles your anchor's (link's) click event? Or navigate using location from your link. That would make more sense.




回答3:


$("div.overlay").each(function(i,n){                
         $(n).click(function(e){
             //do not need "a" in front of it as #overlink is unique anyways
             $('#overlink').trigger('click'); // id of shadowbox link

             return false;

             });


       });

try this and note my comment above your trigger




回答4:


Have you tried:

 $('a#overlink').click();



回答5:


Try this:

$("div.overlay").each(function(){                
  $(this).click(function(){
      var $elm = $('a#overlink');
      if (document.createEvent) {
        var e = document.createEvent('MouseEvents');
        e.initEvent( 'click', true, true );
        $elm.get(0).dispatchEvent(e);
      }
      else {
        $elm.trigger("click");
      }
     return false;
  });
});


来源:https://stackoverflow.com/questions/6494159/jquery-triggerclick-not-working-in-ie-object-does-not-support-this-prope

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!