Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to highlight the table row using jquery in Rails 3?
    primarykey
    data
    text
    <p>I have successfully installed jquery-rails in my rails 3 test app. I already had it working. Can somebody pls point out to me how to make this jquery code I got from Sreekumar yesterday to work on my rails 3 test app. </p> <p>Here is the jquery code and I placed this on <b><code>application.js</code></b>:</p> <pre><code>$(document).ready(function() { $('#table_list').find('tr&gt;td').hover(function() { //$(this).css("background-color", "green"); $('table_list').addClass('highlight'); }, function() { //$(this).css("background-color", "inherit"); $('table_list').removeClass('highlight'); }); $('#table_list tr:even').addClass('even'); $('#table_list tr:odd').addClass('odd'); }); </code></pre> <p>The objective of this code is to make the tables row color alternate and highlight the selected row. Alternating the row color works perfectly fine, however, the highlight is not working. </p> <p>Here is the rails 3 code in <b><code>index.html.erb</code></b>:</p> <pre><code>&lt;h1&gt;Listing Ninjas&lt;/h1&gt; &lt;table id="table_list"&gt; &lt;tr&gt; &lt;th&gt;Name&lt;/th&gt; &lt;th&gt;Rank&lt;/th&gt; &lt;th&gt;Village&lt;/th&gt; &lt;th&gt;Country&lt;/th&gt; &lt;th&gt;&lt;/th&gt; &lt;th&gt;&lt;/th&gt; &lt;th&gt;&lt;/th&gt; &lt;/tr&gt; &lt;% @ninjas.each do |ninja| %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= ninja.name %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= ninja.rank %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= ninja.village %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= ninja.country %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= link_to 'Show', ninja %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= link_to 'Edit', edit_ninja_path(ninja) %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= link_to 'Destroy', ninja, :confirm =&gt; 'Are you sure?', :method =&gt; :delete %&gt;&lt;/td&gt; &lt;/tr&gt; &lt;% end %&gt; &lt;/table&gt; &lt;br /&gt; &lt;%= link_to 'New Ninja', new_ninja_path %&gt; </code></pre> <p>And here is my css code which is in a separate file <b><code>application.css</code></b>:</p> <pre><code>#table_list{ border: solid 1px #666; border-collapse: collapse; margin: 10px 0; } #table_list th{ font-size: 12px; color: #FFF; background-color: #404C99; padding: 4px 8px; padding-bottom: 4px; text-align: left; } #table_list .highlight { background-color: yellow; } #table_list td { font-size: 12px; padding: 2px 6px; } #table_list .even td { background-color: #E3E6FF; } #table_list .odd td { background-color: #D1D8F6; } </code></pre> <p>All of the 3 codes are in separate files.</p> <p>I'm kinda new to rails and jquery. Im still a beginner. Pls be patient...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload