Hey folks.
I am trying to apply a function to multiple tables all with different
IDs. I got about halfway through copying and pasting the function and
just changing the ID before I realized this was absurd. But I don''t
know how to do this smarter with Prototype. Here is the function:
Event.addBehavior({
''table#BULLETINS'': function() {
var links = $$(''table#BULLETINS
tr.header'').first().getElementsByTagName(''a'');
for (i=0; i<links.length; i++){
var link = links[i];
link.onclick = function() {return false;}
}
}
});
So, I was copying this same code, changing "BULLETINS" to whatever ID
I required. How do you parametrize this exactly? I have an arbitrary
number of different IDs to apply this to, but I don''t know how to get
Prototype to watch for *any* of them, and then use the found ID,
whichever it is, in this function.
Amiri
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
1) Simply get all tables (if those that you need are the only ones on
the page):
$$(''table'');
2) Assign a unique class to all of the tables, then do:
$$(''table.myUniqueClassName'');
3) Specify id''s directly in selector expression (if the amount of
tables is not too high):
$$(''table#foo, table#bar, table#baz'');
4) Get all tables with id attribute:
$$(''table[id]'');
etc.
-- kangax
On Jul 3, 3:13 pm, Amiri
<amiribarksd...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Hey folks.
>
> I am trying to apply a function to multiple tables all with different
> IDs. I got about halfway through copying and pasting the function and
> just changing the ID before I realized this was absurd. But I
don''t
> know how to do this smarter with Prototype. Here is the function:
>
> Event.addBehavior({
> ''table#BULLETINS'': function() {
> var links = $$(''table#BULLETINS
> tr.header'').first().getElementsByTagName(''a'');
> for (i=0; i<links.length; i++){
> var link = links[i];
> link.onclick = function() {return false;}
> }
> }
>
> });
>
> So, I was copying this same code, changing "BULLETINS" to
whatever ID
> I required. How do you parametrize this exactly? I have an arbitrary
> number of different IDs to apply this to, but I don''t know how to
get
> Prototype to watch for *any* of them, and then use the found ID,
> whichever it is, in this function.
>
> Amiri
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
On Jul 3, 3:27 pm, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 1) Simply get all tables (if those that you need are the only ones on > the page): > $$(''table''); > > 2) Assign a unique class to all of the tables, then do: > $$(''table.myUniqueClassName''); > > 3) Specify id''s directly in selector expression (if the amount of > tables is not too high): > $$(''table#foo, table#bar, table#baz''); > > 4) Get all tables with id attribute: > $$(''table[id]''); >I think 3 is what I need. That will most directly enable me to control explicitly which tables the function gets applied to. I don''t like the "grab em all and winnow them" approaches. Thank you, kangax! Amiri --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---