开发者

jQuery - manually trigger link inside of a <div> that gets clicked on [duplicate]

This question already has answers here: Closed 10 years ago.

Possible Duplicate:

How can I simulate an anchor click vi开发者_Python百科a jquery?

For some reason I thought this would be really easy. Here's my code:

$('#someDamnedDiv').live('click', function () {
    $('a', this).trigger('click');
});

What the Sam Hill is wrong with my function?


I don't think it's possible to simulate a click on a link. Look here. However, you could do this:

$('#someDamnedDiv').live('click', function (event) {
    window.location = $(this).find('a').attr('href');
    event.preventDefault();
});


this is what i use for one of my projects:

$('div.classname').click(function(e){
    if($(e.target).is('a')) return;
    $(this).find('a').click();
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜