Triggering a click event issues via (event.button != 0)
I have an object that has a click event I'm trying to trigger. However in the click event I have the following if statement: if(event.button != 0){return true;}
This if statement allows right clicks to go through and activate but it also prevents me from triggering the event. Any ideas on how to prevent this? If I remove the if statement from the first click function everything works as intended.
Here's my example code based off of the trigger event examples:
- <!DOCTYPE html>
<html>
<head>
<style>
button { margin:10px; }
div { color:blue; font-weight:bold; }
span { color:red; }
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<a href="#" class="quoteLink">Button #1</a>
<a href="#" class="quotelink2">Button #2</a>
<div><span>0</span> button #1 clicks.</div>
<div><span>0</span> button #2 clicks.</div>
<script>
$(".quoteLink").live("click", function(event){
if(event.button != 0){return true;}
update($("span:first"));
});
$(".quotelink2").live("mouseover", function(event){
$(".quoteLink").trigger('click');
update($("span:last"));
});
function update(j) {
var n = parseInt(j.text(), 10);
j.text(n + 1);
}
</script>
</body>
</html>