When using jQuery to create dynamic buttons, is there a way to add a CSS class to the button during creation without needing an extra line of JavaScript to add the class afterwards? Below is a example code snippet:
$.each(data, function (index, value) {
var button = $('<button/>', {
text: value,
id: 'btn_' + index,
click: function () { MNS.ButtonClick(this) }
});
$('#MyDiv').append(button);
});
Is it possible to achieve this instead?
$.each(data, function (index, value) {
var button = $('<button/>', {
text: value,
id: 'btn_' + index,
**css:'Myclass'**
click: function () { MNS.ButtonClick(this) }
});
$('#MyDiv').append(button);
});