Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Given that you have the HTML look like this:</p> <pre><code>&lt;div class="accordion" id="accordion2"&gt; &lt;div class="accordion-group"&gt; &lt;div class="accordion-heading"&gt; &lt;a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseOne"&gt; Group Item #1 &lt;/a&gt; &lt;/div&gt; &lt;div id="collapseOne" class="accordion-body collapse in"&gt; &lt;div class="accordion-inner"&gt; &lt;div class="element"&gt;blach blah blah&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="accordion-group"&gt; &lt;div class="accordion-heading"&gt; &lt;a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseTwo"&gt; Group Item #2 &lt;/a&gt; &lt;/div&gt; &lt;div id="collapseTwo" class="accordion-body collapse"&gt; &lt;div class="accordion-inner"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>Then in order to target the div with class "accordion-inner" you'll have to use <code>.siblings('.accordion-inner')</code>, since <code>.find()</code> looks for descendants.</p> <p><code>.siblings()</code> gets the siblings of an element (elements in the same level).</p> <p>Update: Forgot you need to do a <code>.find()</code> once you've found the sibling.</p> <p>Thus the example would be:</p> <pre><code>$('.accordion-heading').on('click', function () { var inner = $(this).siblings('.accordion-body').find('.accordion-inner'); if ($.trim(inner.html()).length == 0) { inner.html('No items'); } }); </code></pre> <p>Thus your javascript should be included like this:</p> <pre><code>&lt;script type="text/javascript"&gt; $(document).ready(function() { $(function () { $.views.AllItems.Init(); }); $('.accordion-heading').on('click', function () { var inner = $(this).siblings('.accordion-body').find('.accordion-inner'); if ($.trim(inner.html()).length == 0) { inner.html('No items'); } }); }); &lt;/script&gt; </code></pre>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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