Topic: Toggle elements

Hi everyone,

I have an un-ordered list as such:

<ul id="activity_<%= -%>">
    <li><%= a.title -<li>
    <li><%= link_to_remote 'Learn more', {:controller => 'activities', :action => 'view', :id =>}, {} -%></li>
    <li class="detail" style="display: none;"><%= a.some_value -%></li>
    <li class="detail" style="display: none;"><%= a.some_other_value -%></li>

I would like to toggle the visibility of the <li>s that are classed 'detail' when the 'Learn more' link is clicked for the corresponding list.

My controller sets up a variable with the ID of the <ul>, which is 'activity_' + params[:id]. When I do + ' li.detail').all('details') do |element, index|

it doesn't work.

What am I doing wrong?


Brandon Taylor
Sr. Developer


Re: Toggle elements

See this thread

Re: Toggle elements

Sweet. Now that's working!

Next stupid question:

I would like to change the HTML of the link that toggled the elements when clicked. When I try to assign a variable to the innerHTML of an element by using:

@link_text = page['activity_' + params[:id] + '_learn'].innerHTML

the page doesn't error out, but also won't work.

Should I just pass in the ID of the element I need to manipulate to an external JavaScript function using 'call'? It seems very difficult to get attribute values of DOM elements within RJS and do something conditionally.

Thanks for the help with the array, I would never have gotten that one!

Brandon Taylor
Sr. Developer