views:

22

answers:

3

Hi, I have a series of buttons and some share the same icons. Presently I'm doing:

        $("#addNewStory").button({icons: {primary: 'ui-icon-plus'}});
    $("#addNewCampaign").button({icons: {primary: 'ui-icon-plus'}});
    $("#addNewAdItem").button({icons: {primary: 'ui-icon-plus'}});

Is there a neater way?

Thx

A: 

OK, sorry, should have tried it first. Solution was just:

$("#addNewStory, #addNewCampaign, #addNewAdItem").button({icons: {primary: 'ui-icon-plus'}});
Roger Walsh
+1  A: 

You can do multiple selectors in the same statement

$("#addNewStory, #addNewCampaign, #addNewAdItem").button({icons: {primary: 'ui-icon-plus'}});
redsquare
+1  A: 

In the general case, if you want to make all elements having id "addNewXXX" to have that button, you could use

        $("[id^='addNew']").button({icons: {primary: 'ui-icon-plus'}});
KennyTM
That's Brilliant!! Thanks! So you are basically saying that if the id 'contains' then do action?
Roger Walsh
@Roger: Yes (technically, ["starts with"](http://api.jquery.com/attribute-starts-with-selector/)).
KennyTM
Magic, thanks a lot
Roger Walsh