Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prototype.js: select elements with id starts with?

There are tags with attributes id like this

<span id="attr35"></span>
<span id="attr44"></span>
<span id="attr23"></span>

Need to set the style to them like this (last two digits might be any)

$("span[id=attr???]").setStyle({'display':'inline'});

Is it possible?

like image 788
Eugene Shmorgun Avatar asked Jul 16 '26 02:07

Eugene Shmorgun


1 Answers

You use valid Selectors API selectors.

$("span[id^=attr]")

If you want more than one match, use $$

$$("span[id^=attr]")

Oops, one more issue. You should use .invoke if you are getting multiple matches. You can't call setStyle directly on the returned set.

$$("span[id^=attr]").invoke("setStyle", ...)
like image 175
I Hate Lazy Avatar answered Jul 17 '26 16:07

I Hate Lazy