I would suggest using a class to identify these buttons (ex: editimage). Then you can easily find them and get their number:
$('.editimage').click(function () { var n = this.id.match(/\d/); loadPopup('Image' + n); }); On Sat, Jan 16, 2010 at 1:44 PM, Peter <floranfe...@gmail.com> wrote: > I have a load of buttons with almost similar names but with a number > identifying them: > id=editimage1 > id=editimage2 > id=editimage3 > id=editimage4 > etc. > > In the onclick event of these buttons I want to do something: > $("#editimage1").click(function() { > loadPopup('Image1'); > }); > > Now I can place this function in my js files as many times as the > button occurs, but that seem rather inefficient. > I'd rather have a single function which I can reuse for all buttons, > something like this pseudocode: > > $("#editimage{imgId}").click(function() { > loadPopup('Image{imgId}'); > }); > > Is that possible? > > Thanks! > > -- > You received this message because you are subscribed to the Google Groups > "jQuery UI" group. > To post to this group, send email to jquery...@googlegroups.com. > To unsubscribe from this group, send email to > jquery-ui+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/jquery-ui?hl=en. > > > > -- Best regards, Balázs Suhajda
-- You received this message because you are subscribed to the Google Groups "jQuery UI" group. To post to this group, send email to jquery...@googlegroups.com. To unsubscribe from this group, send email to jquery-ui+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/jquery-ui?hl=en.