scotchpasta scotchpasta - 1 year ago 78
HTML Question

Using jQuery to select div with class signed by ruby iteration

I'm trying to do a click event where a user clicks a link that toggles a dropdown window. But only one window at a time.

$(".one").on('click', function(){

<div class="row visual_wrap text-center">
<ul class="containerviz no-bullet text-center">
<% @visualizations.each do |visualization| %>
<li class="viz-list-style">
<div class="one <%= %>" style="background-image: url('<%= visualization.cover_image.to_s %>')" ><%= visualization.title %></div>
<div class="two <%= %>">some text to check</div>
<% end %>

Since I'm iterating through a database to bring each visualization to the page. I want a user to select a single visualization that will toggle a dropdown for it. But since I'm differentiating the each visualizations div by their class I'm not sure how to write that in jQuery. Right now the above jQuery will open and close every single visualization if I click any of them. How can I make this more specific? I've tried using an on click event with
. But that did not work.

Answer Source
<script type="text/javascript">
    $(document).ready(function() {
       $('.one').on('click', (function() {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download