$("#first").click(function () {
alert('will click the hidden link now');
// this doesn't work:
// $("#second").click();
// see http://bit.ly/13iCWRw (stackexchange)
$("#second")[0].click();
return false; // abort the original click
});
$("#abortopen").click(function () {
window.open("http://bit.ly/lying-links", "_self");
// alternative:
// window.location = "http://bit.ly/lying-links";
return false;
});
<h2>Click another link</h2>
<ul>
<li><a id="first" href="http://www.google.com">link to google.com (click redirected to hidden link)</a></li>
<li><a id="second" href="http://bit.ly/lying-links">lying links</a>here is a hidden link</li>
</ul>
<h2>Abort click, change location</h2>
<p><a id="abortopen" href="http://www.google.com">link to google.com (click will be aborted and other page opened)</a></p>
#second {
display:none;
}