1

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?

Community
  • 1
  • 1
Halfwarr
  • 7,853
  • 6
  • 33
  • 51

1 Answers1

3

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

$$("[id^=AAA_][id$=_BBB]")
p e p
  • 6,593
  • 2
  • 23
  • 32
  • 1
    Be aware that the `$$()` CSS selector will return an array of elements that you can operate on, vs a jQuery collection – Geek Num 88 Aug 07 '14 at 14:58
  • Yep this worked and did exactly what I wanted. Last question is there any documentation I can find about this? http://api.prototypejs.org/dom/dollar-dollar/ does not mention about using the above syntax. – Halfwarr Aug 07 '14 at 18:00
  • Absolutely. The thing is that these should not be library/framework-specific, but are rather a part of the CSS selector specifications. A library could detect browsers that, for example, do not support certain selectors and provide the behavior via some other means, but I don't have any examples on that, and you'd likely only run into problems in old browsers (IE6). Check out some documentation from Mozilla on attribute selectors, which can be just as well used in plain ol' CSS. https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors – p e p Aug 07 '14 at 19:55
  • 3
    I believe both Prototype and jQuery use the [Sizzle](http://sizzlejs.com/) library so we should consider that as the reference. – clockworkgeek Aug 08 '14 at 14:05