I have a form with inputs (with id’s). And i need to bind one event to click on any input in this form.
Now, I use this construction:
$("#siteAdress").click(function(){
$("#reg-login").click();
});
$("#phoneNumber").click(function(){
$("#reg-login").click();
});
$("#reg-email").click(function(){
$("#reg-login").click();
});
$("#reg-login").click(function(){
// DO SOMETHING
});
How to optimize it?
The easiest way is probably to add a class to all the elements you need to bind on, and use it:
If this is not an option, you can use an
idfor your form, and query all its input children:And if neither is possible, you can always use a comma-separated list of selectors: