Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
156
rated 0 times [  162] [ 6]  / answers: 1 / hits: 87558  / 12 Years ago, sat, november 24, 2012, 12:00:00

I have the following input elements:



<input id=AAA_RandomString_BBB type=text />
<input id=AAA_RandomString_BBB_Start type=text />
<input id=AAA_RandomString_BBB_End type=text />


AAA & BBB are constants and I will always know what they are. However RandomString will always be random.



I want to get the value of AAA_RandomString_BBB. I do not want the values from the input elements with ID ending in either _Start or _End.



I tried the folowing:



$('[id^=AAA_]')


But the above selects all of the input elements that have an ID starting with AAA_



I need some way to select using a regex type syntax like:



$('[id^=AAA_(.+?)_BBB]')


Is this possible? If not, can anyone suggest a method of selecting


More From » jquery

 Answers
8

You can combine both selectors in a multiple attribute selector.



​$([id^=AAA_][id$=_BBB])


It will return all the elements that matches all the specified attribute filters:




  • [id^=AAA_] matches elements with id attribute starting with AAA_, and

  • [id$=_BBB] matches elements with id attribute ending with _BBB.






Another generic alternatives:




[#81826] Thursday, November 22, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
daquanmilesw

Total Points: 57
Total Questions: 102
Total Answers: 110

Location: Wallis and Futuna
Member since Sat, Aug 6, 2022
2 Years ago
daquanmilesw questions
;