jQuery selector for matching at start AND end of ID?

Jquery

Jquery Problem Overview


I have a group of buttons on my web page which all have an id that end with the text "EditMode".

I'm using jQuery to assign an event to like so

$('[id $=EditMode]').click(editHandler);

However now I want to prefix the id with a name (which I will know in advance) so the id would be "aName+someotherstuff+EditMode". How do I alter the above expression so I match on aName AS WELL as editMode?

Jquery Solutions


Solution 1 - Jquery

$('[id ^=aName][id $=EditMode]')

Solution 2 - Jquery

Alternatively, you can use the "add()" function for readability, but I would recommend Chaos's method:

$("[id ^=aName]").add("[id $=EditMode]")

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAJMView Question on Stackoverflow
Solution 1 - JquerychaosView Answer on Stackoverflow
Solution 2 - JqueryRichard ClaytonView Answer on Stackoverflow