Reputation: 1450
I want to make simple Jquery function like this:
function switchButton($param) {
$param.on('change', function() {
var result = $($param +'.switch-field input[name=switch]:checked').val();
alert(result);
});
}
Execute like this:
switchButton(('.switch-field input'));
Please help to format this function correctly. Thank you.
Upvotes: 1
Views: 512
Reputation:
JSFiddle: https://jsfiddle.net/xpvt214o/111367/
function switchButton(element) {
element.on('click', function() {
alert(element[0].id); // do something
});
}
switchButton($('#btn1'));
switchButton($('#btn2'));
Upvotes: 1