trigger a click on a anchor link

后端 未结 2 891
悲&欢浪女
悲&欢浪女 2021-01-25 16:10

I have a collection of links with thumbnails that match them. I need to load these thumbnails as divs with the background image set to them. I\'m using a single image that has a

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-25 16:44

    Hiya Working demo here: http://jsfiddle.net/f6FJ3/19/

    for the trigger reason read this : jQuery: trigger click() doesn't work?

    It's important to clarify that doing jQuery('#open').click() does not execute the href attribute of an anchor tag so you will not be redirected. It executes the onclick event for #open which is not defined.

    below code will get the desired output of window getting open on image click.

    JQuery Code

    $(document).ready(function(){
        $('.tmb').click(function(){
            var target=$(this).parent().find("a");
    
            $("#debug").text("clicked "+target.text());
            //target.triggerHandler('click');
            window.open(target.attr('href'));
    
        });
    });​
    

    Hope this helps, cheers!

提交回复
热议问题