I am iterating through an array in Rails to show a set of articles. I'd like a button to slide Toggle the article open when clicked (so each would be a headline and button, and the text would be revealed on button click).
The array looks like:
<% @articles.each do |article| %>
<div class="article_header">
<h1><%= article.title %></h1>
<button id="clickme" type="button">Show More!</button>
<div class="article_content">
<p><%= markdown article.content %></p>
</div>
<% end %>
</div>
I am then trying to toggle the article_content with the following:
<script>
$( ".article_content" ).hide()
$( "#clickme" ).click(function() {
$( ".article_content" ).slideToggle( "300", function() {
});
});
</script>
After reading some other questions, I believe the issue is that article_content is a class, which is why currently the button opens and collapses all of the content text.
If I am iterating through an array, can I assign different IDs to target as my object so clicking the button for Article 1 opens and closes Article 1 only?