6

Possible Duplicate:
How can I simulate an anchor click via 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?

0

2 Answers 2

7

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();
});
Sign up to request clarification or add additional context in comments.

4 Comments

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 well that looks promising! but I'm not gonna test it in every browser right now :)
There's another question about this subject here
This one does the trick. Thanks.
4

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

1 Comment

Just what I was needing so that hrefs inside of clickable divs are still active. Thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.