views:

476

answers:

1

Hello,

I have the following code:

$(document).ready(function() {
                $("#TestLink").click(function() {
                    $("#LinkHolder").html("test");
    });
});

<span id="LinkHolder">
<a href="SomeLink" id="TestLink" target="_blank">Click here to test</a>
</span>

Everything works like a charm when I click with left mouse button on the link, but when I click it with CTRL+LeftMouseButton or MiddleMouseButton it doesn't work.

Will be glad if someone can help me with this one.

Thanks in advance!

+7  A: 

Consider:

$(document).ready(function() {
                $("#TestLink").mouseup(function(e) {
                    $("#LinkHolder").html("test");
    });
});

As an alternative? This does detect middle mouse button clicks.

Sbm007
And according to this, you can find out which button was clicked by looking at e.button: From http://www.quirksmode.org/js/events_properties.html
lod3n
Forgot to mention that this disables the default behaviour of link clicks, for that add in: window.open($(this).find('a').attr('href'), '_blank);
Sbm007
works perfect. thanks!
RRStoyanov
btw. instead of: window.open($(this).find('a').attr('href'), '_blank); I use $(e).attr("href"); because the action is on the <a link, so with your way it returns "undefined". If the action was on the span, than yours will work too. anyway, your suggestion saves me a lot of time. thanks again
RRStoyanov