Vinai Raj Vinai Raj - 6 months ago 173
jQuery Question

Identify the Click Event in bootstrap touch spin

I am little bit confusion to find the click event in the class using jquery.
my question is how to identify whether I click touchspin down or up
I am using bootstrap touch spin.

<button type="button" class="btn btn-default bootstrap-touchspin-down">-</button>
<input type="number" value="18" onchange="calculatetotal(3)" style="width: 100%; padding: 0px; display: block;" class="ex_limit form-control" readonly="" id="qty3">
<button type="button" class="btn btn-default bootstrap-touchspin-up">+</button>


I Want to calculate some process in when Up botton clicked and some process in down button click.

Here I try to Identify the button using class.

$('.btn, .btn-default, .bootstrap-touchspin-down').click(function(){
alert("down!");
});


Please help me to do this task.

Answer
$('[class*="bootstrap-touchspin-"]').click(function(event) {
  var $this = $(this);

  if ($this.hasClass('bootstrap-touchspin-down')) {
    alert('down');
  } else if ($this.hasClass('bootstrap-touchspin-up')) {
    alert('up');
  }
});

Alternatively:

$('.bootstrap-touchspin-down').click(function(event) {
  alert('down');
});

$('.bootstrap-touchspin-up').click(function(event) {
  alert('up');
});