Selecting Element Which Starts With "abc" And Ends With "xyz"
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']');
Solution 1:
You can use 2 attribute selectors.
$('div[id^="abc"][id$="xyz"]');
Solution 2:
Try the following:
$('div[id^="abc"][id$="xyz"]');
http://api.jquery.com/multiple-attribute-selector/
Solution 3:
Use filter:
$('div')
.filter(function() {
returnthis.id.match(/^abc+xyz$/);
})
.html("Matched!")
;
Post a Comment for "Selecting Element Which Starts With "abc" And Ends With "xyz""