I have the following code:
<div class="test">
<span>some text</span>
<a href="www.test.com">click here</a>
</div>
<div class="test">
<span>some text</span>
<a href="www.test.com">click here</a>
</div>
<div class="test">
<span>some text</span>
<a href="www.test.com">click here</a>
</div>
When the the page loads, using jQuery, I want to apply a click event to every div on the page with the class "test". So when you click on the div, the anchor link within that div is triggered. How is this done? I've tried the following code, but get the error "Uncaught RangeError: Maximum call stack size exceeded"
$( ".test" ).on( "click", function() {
$( this ).find("a").trigger("click");
});
I've also tried the first answer below, which works fine, however, it doesn't handle different link targets like _blank.