Reputation: 88
I have tried many ways i dont know what i miss now
<input id="stopBuy" class="grn" type="button" onclick="selectGT()" value="Buy Now">
Issue in this when we we click once on button and if mouse is over button and then we press enter it get clicked again. so i wanted to know if there is way to stop this?
I tried putting this in whole container but does not work. I have included jQuery v1.8.3
<script>
$('#container').keypress(function(e) { // even try putting #stopBuy
if(e.which == 13) {
e.preventDefault();
}
});
</script>
Upvotes: 2
Views: 84
Reputation: 3412
Blur the button after it is clicked:
$('#stopBuy').click( function() {
$(this).blur();
});
Upvotes: 0
Reputation: 531
Maybe if you stop event propagation ?
$('#container').keypress(function(e) { // even try putting #stopBuy
if(e.which == 13) {
e.preventDefault();
e.stopPropagation();
}
});
Upvotes: 0
Reputation: 38112
Try to put your code inside DOM ready $(document).ready(function() { });
or $(function () { })
to make it work:
$(document).ready(function() {
$('#container').keypress(function(e) { // even try putting #stopBuy
if(e.which == 13) {
e.preventDefault();
}
});
});
Upvotes: 4