Reputation: 57
I need to attach the click event dynamically using JavaScript. My sample code is given below.
require(["dijit/form/ToggleButton", "dojo/dom-construct"], function (ToggleButton, domConstruct) {
var newButton = new ToggleButton({
showLabel: true,
checked: false,
onChange: function (val) { frame(this); },
label: item.getAttribute('label')
}, item.getAttribute('id'));
});
Upvotes: 0
Views: 518
Reputation: 7852
If you are using dojo 1.8+ you can use Widget#on
to connect to events after the widget is created.
var newButton = new ToggleButton({
showLabel: true,
checked: false,
label: item.getAttribute('label')
}, item.getAttribute('id'));
newButton.on('change',function(){
console.log('onChange event called');
});
newButton.on('click',function(){
console.log('click event called');
});
Upvotes: 3
Reputation: 262
use button id attribute to attach click event like
$("#buttonid").click(function(){
//code goes here
})
where buttonid is id attribute of your button
Upvotes: -1