US_User
US_User

Reputation: 57

How to add the click attach event dynamically

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

Answers (2)

BuffaloBuffalo
BuffaloBuffalo

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

abc123
abc123

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

Related Questions