Right now I loop through my RoR objects and create a new jquery function for each separate object. I understand this is extremely inefficient and amateurish, and I would like to have just one jquery function that handles this operation.
<% @startups.each do |startup| %>
<div class="panel-body showVideo<%=startup.id%>">
...
</div>
<div class="panel-body theVideo<%=startup.id%>">
...
</div>
<script type="text/javascript">
$(function () {
$('.theVideo<%=startup.id%>').hide();
$('.showVideo<%=startup.id%>').on('click', function () {
$('.theVideo<%=startup.id%>').show();
$('.showVideo<%=startup.id%>').hide();
});
});
</script>
<% end %>
Basically this code waits for a user to click the div, and hides that div while showing another div. The code currently works, but I don't want to create tons of functions when it could be one!