A. jones A. jones - 6 months ago 23
jQuery Question

prevent mouse middle button to open new tab in anchor tag

Challenge: prevent mouse middle button to open new tab in anchor tag with a particular class.

my problem is I have tried but it stopped working of all anchor tags in page but I don't want it.I want to stop working of middle button to open a new tab in anchor tab having class name tab1.

visit: http://jsbin.com/wemapehadu/edit?html,output

can anybody have solution for that...

Answer

Another simple solution $(function(){ $(document).on("click", function(e){ if($(e.target).is("#google") && e.button===1) e.preventDefault() }) }) JS Bin Google
Bing

[FIDDLE LINK][]

http://jsfiddle.net/kezcrxop/1/