Buttons can be represented with labels; in that case, use a click handler:
jQuery('<label id="'+cycle.apsID+'" class="btn">MahButt</label>')
.appendTo('#'+chartid+'-apsbar')
.on('click', function(){
$(location).attr('href','/v1/parameters/'+this.id+'.html');
});
You can also get the checked state, and prevent the button from being pressed, among other things:
jQuery('<label id="'+cycle.run+'" ...
.on('click', function(e){
var run = this.id;
// Look for the (label->input)
if (this.firstChild.checked)
...
// To prevent checked/pressed state if desired:
e.stopPropagation();
}
Button bars are represented by labels wrapped around inputs:
<div class="btn-group live-buttons" data-toggle="buttons"><div class="btn-group"><label class="btn"><input type="checkbox">text...
In that case use a change handler on the input:
var label = jQuery('<label class="btn btn-sm btn-'+color+'"></label>').appendTo(action_button_bar);
var input = jQuery('<input class="run-'+cmd+'" type="checkbox" autocomplete="off" value="'+cycle.run+'">').appendTo(label)
.on('change', cycle.owned? function(){
patchPick(this.value,'{ "action" : "run-hold" }');
} : function() {
patchPick(this.value,'{ "action" : "run-buy" }');
});
var text = jQuery('<span class="glyphicon glyphicon-'+glyph+'"></span> <span class="hidden-xs">'+cmd+'</span>').appendTo(label);
If you just need clicks from the button bar, you do NOT NEED input:
<div class="btn-group live-buttons" data-toggle="buttons"><div class="btn-group"><label class="btn">text...
Then you can put the change handler right on the label:
var applybar = jQuery('<div id="applybar-'+cycle.run+'" class="btn-group pull-right" data-toggle="buttons" />');
var apply_button = jQuery('<label id="apply-'+cycle.run+'" class="btn btn-sm btn-moneygreen"><span class="glyphicon glyphicon-ok"></span><span class="hidden-xs"> Apply</span></input></label>')
.on('click', function(e) {
// Do work
e.stopPropagation();
})
.appendTo(applybar)
;
|