jQuery - manually trigger link inside of a <div> that gets clicked on [duplicate]
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();
});
精彩评论