I have the following link element:
<a href="javascript:;" onclick="check_show('http://www.test.com')">Test</a>
<script>
function check_show(link){
if($('#testelement).css('display') == 'block'){
window.location.href = link;
}
}
</script>
The problem with this is if I was to click to open in a new window (or ctrl-click), it will open a new windows for ‘javascript:;’. So, I need to ad the link in the the href. This is fine, but I would like to still check #testelement is visible first.
Your javascript is being ran, followed by the browser redirecting to the
href. You need to prevent the browser from following this link. You can do this by addingreturn false;after your function call in youronclick.