How can I control a div from a javascript function. For example if i have a product and has an id=8 and this product has 3 trainees so when i click on something i should see the 3 trainees name for this product. in the code i created a div with id="T<?=product_id?>" (id=T8) class ="LINKSOFF" (hidden) how can i turn the class to class="LINKSON" from a javascript function. The problem is that when i have many div with the same id and write class="LINKSON" i can not see the div. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hey Chich, You might want to brush up on your x/html rules, an ID value should be unique to that page i.e. you should only have one div id=T8 on the page - that or redesign the DOM structure of your page because I believe Prototype is designed with the unique ID rule in mind (This I assume because I''ve never tried to use the same ID on a page) As for changing the style of the div look up SetStyle and AddClassName in the Prototype API docs. HTH On Mon, Apr 14, 2008 at 10:34 AM, chich <ckhelou-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > How can I control a div from a javascript function. > For example if i have a product and has an id=8 and this product has 3 > trainees > so when i click on something i should see the 3 trainees name for > this product. > in the code i created a div with id="T<?=product_id?>" (id=T8) class > ="LINKSOFF" (hidden) > how can i turn the class to class="LINKSON" from a javascript > function. > The problem is that when i have many div with the same id and write > class="LINKSON" i can not see the div. > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
It sounds like you''re violating a basic rule of the DOM: ids must be unique across the document. If you have duplicate ids, you''re violating standards. Once you solve that issue, your best bet is to select multiple elements with Prototype''s $$() function. http://prototypejs.org/api/utility#method-$$ TAG On Apr 14, 2008, at 8:34 AM, chich wrote:> > How can I control a div from a javascript function. > For example if i have a product and has an id=8 and this product has 3 > trainees > so when i click on something i should see the 3 trainees name for > this product. > in the code i created a div with id="T<?=product_id?>" (id=T8) class > ="LINKSOFF" (hidden) > how can i turn the class to class="LINKSON" from a javascript > function. > The problem is that when i have many div with the same id and write > class="LINKSON" i can not see the div. > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hello all, first post here :) For applying styles to several divs you should use class instead of ID. This is a best practice and a standard widely used. ID''s for uniqueness and classes for batch update :) Peace, Zen On Apr 14, 2008, at 3:42 PM, Brian Williams wrote:> Hey Chich, > > You might want to brush up on your x/html rules, an ID value should > be unique to that page i.e. you should only have one div id=T8 on > the page - that or redesign the DOM structure of your page because I > believe Prototype is designed with the unique ID rule in mind (This > I assume because I''ve never tried to use the same ID on a page) > > As for changing the style of the div look up SetStyle and > AddClassName in the Prototype API docs. > > HTH > > > > On Mon, Apr 14, 2008 at 10:34 AM, chich <ckhelou-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > How can I control a div from a javascript function. > For example if i have a product and has an id=8 and this product has 3 > trainees > so when i click on something i should see the 3 trainees name for > this product. > in the code i created a div with id="T<?=product_id?>" (id=T8) class > ="LINKSOFF" (hidden) > how can i turn the class to class="LINKSON" from a javascript > function. > The problem is that when i have many div with the same id and write > class="LINKSON" i can not see the div. > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi chich,
As everyone has mentioned, you will need unique IDs for your HTML
elements. Fortunately, Rails 2.0 has a helper method that will
generate unique IDs for elements given an ActiveRecord object. div_for
is very easy to use:
<% trainees.each do |trainee| %>
<% div_for trainee do %>
<%= link_to_function h(trainee.name),
"my_javascript_function(#{trainee.id})", :class =>
''LINKSON'' %>
<% end %>
<% end %>
...
<script type="text/javascript">
function my_javascript_function(id) {
$("trainee_" + id).class = "LINKSOFF";
}
</script>
So, say you have a trainee record with ID 8, then div_for(trainee)
would generate:
<div id="trainee_8"></div>
Hope this helps.
Jason Arora
On Apr 14, 7:34 am, chich
<ckhe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> How can I control a div from a javascript function.
> For example if i have a product and has an id=8 and this product has 3
> trainees
> so when i click on something i should see the 3 trainees name for
> this product.
> in the code i created a div with id="T<?=product_id?>"
(id=T8) class
> ="LINKSOFF" (hidden)
> how can i turn the class to class="LINKSON" from a javascript
> function.
> The problem is that when i have many div with the same id and write
> class="LINKSON" i can not see the div.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---