Search code examples
regexprototypejs

How can I select an element by ID with Prototype using regex?


My Question is very very similar to this question. Which asks:

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.

Now the anwser for JQuery was the following:

You can combine both selectors in a multiple attribute selector.

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

So is there a way to do the above but using Prototype v1.7.2?


Solution

  • The same thing works in Prototype, using Prototype's syntax of course:

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