Reputation: 5758
Am new to jQuery and I know about class
, id
and name
selectors in jQuery.
In my HTML I have 6 textarea elements whose Ids are unique and there is a particular pattern with which the ID starts(ex: id= "TA1", id= "TA2".. and so on.. ).
My question is, in jQuery is there a way select all these textarea elements whose ID start with a particular pattern and end with a particular pattern ?
Edit: Want the combination of both start and end patterns
Upvotes: 3
Views: 1796
Reputation: 8779
If you pattern for IDs is simple (begins with a
ends with b
), than you can use
$('textarea[id^="a"]').filter('[id$="b"]');
for more complex patterns you can use James Padolsey's filter that allows to use regular expressions like
$("textarea:regex(id, a.*some-text-in-the-middle.*b)");
Documentation on standard jQuery selectors you can find here
Upvotes: 1
Reputation: 9146
You ca use the selector like
$('textarea[id^="TA"]');
Selects elements that have the specified attribute with a value beginning exactly with a given string.
Edit: for combining you can use like this, let see the ending patters is *22,*32,**42 so "2" is ur ending pattern.
$('textarea[id^="TA"]').filter('[id$="2"]');
Upvotes: 2