codeMan
codeMan

Reputation: 5758

How to select all the Textareas which have their id in a particular pattern

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

Answers (5)

Vadim
Vadim

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

Sarath
Sarath

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

palaѕн
palaѕн

Reputation: 73896

Try this:

$('textarea[id^="TA"]')

Upvotes: 4

VisioN
VisioN

Reputation: 145388

Use attribute starts-with selector:

$("[id^='TA']"). ...

Upvotes: 4

Sudhir Bastakoti
Sudhir Bastakoti

Reputation: 100175

try doing like:

$("textarea[id^='TA']");

Upvotes: 4

Related Questions