Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery animate dynamically rendered partials
    primarykey
    data
    text
    <p>Disclaimer: I'm new to jQuery and js. </p> <p>I'm trying to hide parts of partials rendered in the user's profile with jQuery. I render collection of user records:</p> <pre><code>&lt;ul class="records"&gt; &lt;%= render @work_records %&gt; &lt;/ul&gt; </code></pre> <p>and in partial file I'm using following code: </p> <pre><code>&lt;li&gt; &lt;div&gt; part to be visible &lt;/div&gt; &lt;div class="container"&gt; &lt;a href="javascript:void(0);" onclick="ShowDetails();"&gt;Show details&lt;/a&gt; &lt;script type="text/javascript"&gt; function ShowDetails() { $("#work_details_&lt;%= work_record.id %&gt;").slideToggle("fast"); } &lt;/script&gt; &lt;/div&gt; &lt;div class="profile_details" id="work_details_&lt;%= work_record.id %&gt;" style="display: none;"&gt; part to be hidden &lt;/div&gt;&lt;/li&gt; </code></pre> <p>This renders all user records and creates link as expected. When I analyze the html looks as expected (id's are unique and match in each partial)</p> <p>Now, I'm not exactly sure where to look for the issue (close to none experience with js) since the only partial that slides is the <em>last one</em>. If I click on the link on other partials than it slides the last one. Any thoughts? </p> <p>UPDATE: here is the HTML produced by the code(stripped down out of irrelevant parts)</p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;div class="container"&gt; &lt;div class="row"&gt; &lt;div class="span6"&gt; &lt;ul class="records"&gt; &lt;li&gt; &lt;div&gt; &lt;h1&gt;Partial title&lt;/h1&gt; &lt;/div&gt; &lt;div class="container"&gt; &lt;a href="javascript:void(0);" onclick="ShowDetails();"&gt;Show details&lt;/a&gt; &lt;script type="text/javascript"&gt; function ShowDetails() { $("#work_details_1").slideToggle("fast"); } &lt;/script&gt; &lt;/div&gt; &lt;div class="profile_details" id="work_details_1" style="display: none;"&gt; Content of partial that needs to be hidden &lt;/div&gt; &lt;/li&gt; &lt;li&gt; &lt;div&gt; &lt;h1&gt;Partial title&lt;/h1&gt; &lt;/div&gt; &lt;div class="container"&gt; &lt;a href="javascript:void(0);" onclick="ShowDetails();"&gt;Show details&lt;/a&gt; &lt;script type="text/javascript"&gt; function ShowDetails() { $("#work_details_3").slideToggle("fast"); } &lt;/script&gt; &lt;/div&gt; &lt;div class="profile_details" id="work_details_3" style="display: none;"&gt; Content of partial that needs to be hidden &lt;/div&gt; &lt;/li&gt; &lt;li&gt; &lt;div&gt; &lt;h1&gt;Partial title&lt;/h1&gt; &lt;/div&gt; &lt;div class="container"&gt; &lt;a href="javascript:void(0);" onclick="ShowDetails();"&gt;Show details&lt;/a&gt; &lt;script type="text/javascript"&gt; function ShowDetails() { $("#work_details_4").slideToggle("fast"); } &lt;/script&gt; &lt;/div&gt; &lt;div class="profile_details" id="work_details_4" style="display: none;"&gt; Content of partial that needs to be hidden &lt;/div&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/body&gt; </code></pre> <p></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.
    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