开发者

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

开发者 https://www.devze.com 2023-01-23 01:54 出处:网络
This question already has answers here: Closed 10 years ago. Possible Duplicate: How can I simulate an anchor click vi开发者_Python百科a jquery?
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

精彩评论

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