Reputation: 1798
I have declared the same structure:
<div class="btn-group" data-toggle="buttons" style="margin-left:50px;">
<label class="btn btn-default">
<input id="past5m" type="radio"> 5m
</label>
<label class="btn btn-default">
<input id="past1h" type="radio"> 1h
</label>
</div>
which, according to this should enable me to attach an onclick
event by adding:
$(document).ready(function() {
$('#past5m').click(function() {
alert('hello');
});
});
JQuery is already included in the code.
However, when `#past5m' is pressed, nothing happens.
Can you please help me to spot the error?
Thanks.
Upvotes: 1
Views: 5945
Reputation: 3723
You click the label, not the value. Try
$(window).ready(function() {
$('#past5m').closest('label').click(function() {
alert('hello');
});
});
Try it on JSFiddle
Upvotes: 3
Reputation: 1798
Ok, figured it out thanks to this:
$(document).ready(function() {
$('#past5m').change(function() {
alert('hello');
});
});
Upvotes: 2