Let me offer a broader answer, given what you have not mentioned yet, but find useful.
For your current problem, the answer
$("div[id^='editDialog']");
The carriage (^) is taken from regular expressions and means starts with .
Solution 1
// Select elems where 'attribute' ends with 'Dialog' $("[attribute$='Dialog']"); // Selects all divs where attribute is NOT equal to value $("div[attribute!='value']"); // Select all elements that have an attribute whose value is like $("[attribute*='value']"); // Select all elements that have an attribute whose value has the word foobar $("[attribute~='foobar']"); // Select all elements that have an attribute whose value starts with 'foo' and ends // with 'bar' $("[attribute^='foo'][attribute$='bar']");
attribute in the above code can be changed to any attribute that this element can have, for example href , name , id or src .
Decision 2
Use classes
// Matches all items that have the class 'classname' $(".className"); // Matches all divs that have the class 'classname' $("div.className");
Decision 3
List them (also noted in previous answers)
$("#id1,#id2,#id3");
Decision 4
If you improve regex (never been used, one's solution has always been sufficient, but you never know!
// Matches all elements whose id takes the form editDialog-{one_or_more_integers} $('div').filter(function () {this.id.match(/editDialog\-\d+/)});
Luke Madhanga Apr 23 '14 at 18:14 2014-04-23 18:14
source share