JQuery bind function to multiple objects
How can we edit the code below to bind this function to both myLink
and myButton
.
if (section === x) {
myButton = $("#a");
myLink = $("#b");
} else {
myButton = $("#c")开发者_高级运维;
myLink = $("#d");
}
myLink.click(function(e) {
e.preventDefault();
showMyDialog();
});
if (section === x) {
$("#a,#b").click(OnClick);
} else {
$("#c,#d").click(OnClick);
}
function OnClick(e) {
e.preventDefault();
showMyDialog();
});
if (section === x) {
$("#a,#b").addClass('clickable');
} else {
$("#c,#d").addClass('clickable');
}
$('.clickable').click(function(e) {
e.preventDefault();
showMyDialog();
});
if (section === x) {
myButton = $("#a, #b");
} else {
myButton = $("#c, #d");
}
myButton.click(function(e) {
e.preventDefault();
showMyDialog();
});
精彩评论