Reputation: 71
I had a look through others similar questions and I haven't got a clue why mine solution doesn't work. Maybe you can spot something I'm missing. What I'm trying to do is trigger a click while clicking on div with id badge
HTML
<div id="call-out">
<div id="badge">Brochure</div>
<p>Add <a href="http://www.google.com" target="_blank">test</a> content</p>
</div>
jQuery:
$('#badge').on('click', function(e) {
e.stopImmediatePropagation();
if (! $(e.target).is('a')) {
$(this).parent('div').find("a").trigger('click');
}
});
Any suggestions appreciated. Here is my test: http://jsfiddle.net/m89wa/2/
Upvotes: 0
Views: 68
Reputation: 56
change: $(this).parent('div').find("a").trigger('click');
try: location.href = $(this).parent('div').find("a").attr("href");
Upvotes: 2
Reputation: 1315
If you call the click
function without an argument on a jquery element, it will trigger the click event on that element.
$('#badge').on('click', function(e) {
e.stopImmediatePropagation();
$(this).parent().find('a').click();
});
Upvotes: 0
Reputation: 82241
Try this:
$('#badge').on('click', function(e) {
e.stopImmediatePropagation();
$(this).parent().find('a').trigger('click');
});
Upvotes: 0