I have 2 radio controls:
<fieldset id="sort">
<label for="sort">Sort: </label>
<input class="sortDirection" type="radio" id="asc" name="sortDirection"><label for="asc">asc</label>
<input class="sortDirection" type="radio" id="desc" name="sortDirection"><label for="desc">desc</label>
</fieldset>
Here's the jquery I am using:
$(document).ready(function(){
$('#sort').buttonset();
});
$('#asc').on("change", function(event){
alert("CHANGE EVENT!");
});
I also tried (with same results):
$('#sort input[type="radio"]').on("change", function(event){
alert("CHANGE EVENT!");
});
The alert is never executed. What am I doing wrong here?
Events must be within the $(document).ready or window.onload
this code :
$(document).ready(function(){
$('#sort').buttonset();
});
should be
$(document).ready(function(){
$('#sort').buttonset();
// events
$('#asc').on("change", function(event){
alert("CHANGE EVENT!");
});
});
$(document).on("change", ".sortDirection", function(){
alert("changed");
//insert code here
});
EXAMPLE
I would suggest using the change
event instead of the click
event. change
does not fire again when the same option is click
ed twice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With