views:

15

answers:

0

Hi,

I am creating navigation for a list of categories. When a user click the link I want to change the background color of the link to show that it is currently selected. I get that to work this code:

<% get_category_list.each do |c| %>
      <li><%= link_to_remote "#{c}", {:update => "list_inner", :success => " $('#{c}').setStyle({backgroundColor: '#303030'});", :url => {:controller => :opinions, :action => :category_content, :id => "#{c}"}}, :id => c, :class => 'categories' %></li>
<% end %>

The only problem is when a user clicks a new category link it keeps changing the background and not removing the prior link background.

So I've been trying this code to search for any link with the class name 'categories' and change them all back to regular background color.

<% get_category_list.each do |c| %>
      <li><%= link_to_remote "#{c}", {:update => "list_inner", :success => "$$('a[class*=\"categories\"]').setStyle({backgroundColor: '#1E1E1E'}); $('#{c}').setStyle({backgroundColor: '#303030'});", :url => {:controller => :opinions, :action => :category_content, :id => "#{c}"}}, :id => c, :class => 'categories' %></li>
<% end %>

The only problem is that doesn't work.

Any advice on how I can solve this problem?

Thank you