2

I have elements in my page with ids like "abc_1_2_3_xyz" .How do I select element in Jquery which starts with "abc" and ends with "xyz"?

$('div[id^="abc"], div[id$="xyz"]');
Mike
  • 675
  • 2
  • 10
  • 20

3 Answers3

5

You can use 2 attribute selectors.

$('div[id^="abc"][id$="xyz"]');
Ram
  • 140,563
  • 16
  • 160
  • 190
4

Try the following:

$('div[id^="abc"][id$="xyz"]');

http://api.jquery.com/multiple-attribute-selector/

Andrew Clark
  • 192,132
  • 30
  • 260
  • 294
0

Use filter:

$('div')
    .filter(function() {
        return this.id.match(/^abc+xyz$/);
    })
    .html("Matched!")
;
KingKongFrog
  • 13,298
  • 19
  • 67
  • 121