tags:

views:

35

answers:

3

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?

+2  A: 

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();
});
cambraca
@cambraca, seems like one of the answers to that question actually does show a cross-browser way to do this! See the answer referencing Selenium...
Ryley
@Ryley well that looks promising! but I'm not gonna test it in every browser right now :)
cambraca
There's another question about this subject [here](http://stackoverflow.com/questions/1421584/how-can-i-simulate-a-click-to-an-anchor-tag)
cambraca
This one does the trick. Thanks.
PolishedTurd
A: 

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();
});
code90