JQuery - a manual trigger link inside a <div> clicked on

Possible duplicate:
How can I simulate binding using jquery?

For some reason, I thought it would be very simple. Here is my code:

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

What is Sam Hill wrong about my function?

+6
jquery
source share
2 answers

I do not think that you can simulate a click on a link. Take a look here . However, you can do this:

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

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(); }); 
+4
source share

All Articles