I have the following code:
var buttonOne = $("#buttonOne");
var buttonTwo = $("#buttonTwo");
// opens an already initialized modal window
(buttonOne, buttonTwo).click(function()
{
modalBoxContainer.dialog("open");
});
This is not working. It will work if I use the elements, but not with the variables.
Any ideas?
Use the .add method.
buttonOne.add(buttonTwo).click(...);
Try combining the selector?
$("#buttonOne, #buttonTwo").click(...
Although you should really use on (jQuery 1.7) or delegate for pre-1.7, this will create the one event for all elements in the handler. Something like:
$(document).on("click", "#buttonOne, #buttonTwo", function () {
//function here
});
on documentation: http://api.jquery.com/on/
delegate documentation: http://api.jquery.com/delegate/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With