Note that there are some explanatory texts on larger screens.

plurals
  1. POJQuery Accordion: Swap Bootstrap Icons
    primarykey
    data
    text
    <p>I'm trying to integrate an accordion into my web app, and I'd like to switch between a chevron-down and chevron-up icon when a header is clicked. Right now, it seems like what I have is only working for every other accordion instance (I have a page of blog entries with comments for each, and the comments are expandable). What am I doing wrong?</p> <p><strong>comments.html.erb</strong></p> <pre><code> &lt;div class="userComments"&gt; &lt;div class="accordion"&gt; &lt;h5 class="icon-chevron-down"&gt; Comments (&lt;%=step.comment_threads.count%&gt;)&lt;/h5&gt; &lt;div class="comment"&gt; &lt;div class="userIcon"&gt; &lt;%= image_tag(current_user.avatar_url(:thumb), :class=&gt;"commentAvatar img-polaroid")%&gt; &lt;/div class="addComment"&gt; &lt;%= semantic_form_for([@project, step, step.comment_threads.build]) do |f| %&gt; &lt;div class="field"&gt; &lt;%= f.text_area :body %&gt; &lt;/div&gt; &lt;div class="submit"&gt; &lt;%= f.submit :comment, :class=&gt; "btn btn-small btn-primary commentSubmit" %&gt; &lt;/div&gt; &lt;% end %&gt; &lt;div class="clear"&gt;&lt;/div&gt; &lt;div class="stepComments"&gt; &lt;% if step.comment_threads.count &gt;0 %&gt; &lt;% step.comment_threads.each do |stepComment| %&gt; &lt;% if stepComment.body.length&gt;0 %&gt; &lt;%= render :partial =&gt; 'comments', :locals =&gt; {:comment=&gt; stepComment, :step=&gt;step} %&gt; &lt;% end %&gt; &lt;% end %&gt; &lt;% end %&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p><strong>comment.js</strong></p> <pre><code> (function($) { $('.accordion').accordion({ collapsible: true, heightStyle: "content", active: false, }); $('.accordion h5').hover(function(){ $(this).css("color", "#0769AD"); }, function(){ $(this).css("color", "#000"); }); $('.accordion h5').click(function(){ console.log('switching'); if($(this).hasClass("icon-chevron-down")){ $(this).removeClass("icon-chevron-down"); $(this).addClass("icon-chevron-up"); } else{ $(this).removeClass("icon-chevron-up"); $(this).addClass("icon-chevron-down"); } }); })(jQuery); </code></pre> <p><img src="https://i.stack.imgur.com/ohxxs.png" alt="enter image description here"></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