Reputation: 990
How do I combine two functions to one ?
Basicially I like to run a function if the last element of
variant--group
"change"` or is "checked"
"change" function:
$(".variant--group").last().find(".option--input").on("change", function() {
//alert
});
"checked" function:
$(".variant--group").last().find(".option--input").attr("checked", function() {
//alert
});
Upvotes: 0
Views: 59
Reputation: 199
You do not need two functions to check for a change for different input types. The .on("change") event will fire for a checkbox or textbox when the value is changed. After the event fires and a change is found, you may want to check if the checkbox is checked or not, to do so see below:
$(".variant--group").last().find(".option--input").is(":checked")
Upvotes: 0
Reputation: 516
Try this
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(document).on('change','.option',function(){
alert('Changed');
});
});
</script>
<body>
<select class="option">
<option>apple</option>
<option>mango</option>
<option>orange</option>
</select>
Car<input type="checkbox" class="option" value="Car" />
Bike<input type="checkbox" class="option" value="Bike" />
Upvotes: 1
Reputation: 888
Looks like you want a single event handler function for 2 events You can combine 2 event handlers together using the following syntax
$("<Selector>").on("change blur",function(){
// alert
});
working fiddle http://codepen.io/anon/pen/EKqJaw
Upvotes: 0