Can anyone please help to explain what does this code do? Specifically what does "id*=section." mean?
Prototype script $$('span[tab_caption="abcd"]')[0].select('span[id*=section.]')[0]
Can anyone please help to explain what does this code do? Specifically what does "id*=section." mean?
Prototype script $$('span[tab_caption="abcd"]')[0].select('span[id*=section.]')[0]
I suspect the '.' might be a typo but i'm not sure. What this appears to be doing is find the first span with attribute tab_caption=abcd
then within that element, find the first span with id of *section*
.
When I try this with the trailing '.', I get an error from prototype saying Syntax error, unrecognized expression: [id*=section.]"
. But without the '.' things work out.
Looking at a sample piece of DOM like this
<span tab_caption="ac">
span ac
<span id="section1">section1</span>
</span>
<span tab_caption="ad">
span ad
<span id="section2">section2</span>
</span>
<span tab_caption="ac">
span ac
<span id="section3">section3</span>
</span>
<span tab_caption="ad">
span ad
<span id="section4">section4</span>
</span>
Then running those selectors in the console I get:
> $$('span[tab_caption="ac"]')[0].select('span[id*=section]')[0]
<span id="section1">section1</span>
> $$('span[tab_caption="ad"]')[0].select('span[id*=section]')[0]
<span id="section2">section2</span>
As you can see, the first query picked the first span with tab_caption=ac
and gave me section1. The second picked the first from tab_caption=ad
and gave me the first section*
match which was section2
.
Are you sure the '.' is supposed to be in the select
argument?
This attribute selector was added with CSS3 and matches any attribute which contains the specified substring. In your case, any span element which has an id attribute with the string section.
somewhere in it.