kk_
kk_

Reputation: 292

Semantic Ui Accordion get number of elements

I'm using a Semantic Ui accordion and want the user to be able to print the accordion with all elements. (It's like a FAQ accordion)
Is there a way to open all accordion elements or get the index of the last element?
Here is my javascript code:

$('.print-btn').on('click', function(){
    $('.ui.accordion').accordion('open', 0);;
    setTimeout(function() { //wait a second until the accordion is opened
        print();
    }, 1000);
});  

This would open the first element and then print it. So I practically need a loop to open all elements and for that I need the number of elements.
I don't know the number of elements beforehand, because the data can change through the database.

Upvotes: 0

Views: 648

Answers (1)

hsrv
hsrv

Reputation: 1570

You can mark all your FAQ items with a specific class and get all items with the specified class selector (I use jQuery here):

var items = $('.faq-item.ui.accordion');

After that it's trivial to go through each item from the array items and open them with a for-loop:

for (int i=0; i<items.length; i++) {
  items.accordion('open', i)
});

Upvotes: 1

Related Questions