Possible Duplicate:
Can I call jquery click() to follow an <a> link if I haven’t bound an event handler to it with bind or click already?
I wrote the following code.
<div style="background-color:orange">Click me to open the link
<br>
<a target="_blank" href="http://example.com">Link</a>
</div>
<script>
jQuery('div').click(function(){
jQuery('a').click();
});
jQuery('a').click(function(e){
alert('It came here!');
e.stopPropagation();
return true;
});
</script>
But the link is not opening.
UPDATE: added target attribute to A-tag.
First of all, you are using a selector that will match all
<a>tags on your page. Perhaps you want to give your<a>an id attribute so that you can target one specific element…You could also try use the
triggerfunction to simulate a click on the element –One last thing to mention is that you didn’t actually call the method to open the link. You can try use this code –
Reference –
trigger()