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.
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.
Share Improve this question edited May 23, 2017 at 12:02 CommunityBot 11 silver badge asked Oct 4, 2014 at 14:53 Eleonora CiceriEleonora Ciceri 1,7983 gold badges17 silver badges34 bronze badges 3-
use
$(document).ready
or$(window).load
– Pranav C Balan Commented Oct 4, 2014 at 14:55 - Do you have jquery installed – loveNoHate Commented Oct 4, 2014 at 14:56
- jsfiddle/xpavghyb – Pranav C Balan Commented Oct 4, 2014 at 14:57
2 Answers
Reset to default 3You click the label, not the value. Try
$(window).ready(function() {
$('#past5m').closest('label').click(function() {
alert('hello');
});
});
Try it on JSFiddle
Ok, figured it out thanks to this:
$(document).ready(function() {
$('#past5m').change(function() {
alert('hello');
});
});