I have the following piece of code:
$(".select").click(function(){
$("input").val($(this).text()).change();
});
$("input").change(function(){
alert($(this).val());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text">
<button class="select">1</button>
<button class="select">2</button>
<button class="select">3</button>
<button class="select">4</button>
Here, when I select the same value by clicking a <button>, the .change() function gets fired anyways which makes it no different from any other function i.e. ruins its specialization of being triggered only on change in value.
A similar question exists on SO, but it does not give any answer to this issue.
How to solve this issue?
.change()if I'm the one who is supposed to check the value?.change()method without using any conditions?