1

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.

Community
  • 1
  • 1
Eleanore
  • 1,750
  • 3
  • 16
  • 33

2 Answers2

3

You click the label, not the value. Try

$(window).ready(function() {

    $('#past5m').closest('label').click(function() { 
        alert('hello'); 
    });
});

Try it on JSFiddle

Barry
  • 3,683
  • 1
  • 18
  • 25
2

Ok, figured it out thanks to this:

$(document).ready(function() {
    $('#past5m').change(function() { 
        alert('hello'); 
    });
});
Community
  • 1
  • 1
Eleanore
  • 1,750
  • 3
  • 16
  • 33