WordPress.org

Ready to get started?Download WordPress

Forums

Q and A FAQ and Knowledge Base for WordPress
Active or current class (5 posts)

  1. berbercito
    Member
    Posted 3 months ago #

    Hi, I have just come across your nice plugin. It does exactly what I was looking for however I think it would be even nicer if it could detect the opened accordion and add to its toggle link an active class name. This way we can style it the way we want.
    Do you think it is easy to be done.
    Thanks a lot in advance.

    https://wordpress.org/plugins/q-and-a/

  2. bnafz
    Member
    Posted 3 months ago #

    I would also like this ability.

    Anyone know how this could be accomplished? I've tried a few things with jQuery but my knowledge with jQuery is limited.

    Thanks in advance.

  3. Tsun4Ever
    Member
    Posted 3 months ago #

    Hi guys,

    i just needed this function also for one of my project, here is my quick solution :

    A bit off css
    `a {
    background: transparent url(img/sprites.png) -50px 0 no-repeat;
    padding-left: 25px;
    &.active {
    background-position-y: -26px;
    }
    }`

    a bit of javascript :

    if ($('.faq-list').length >0) {
                $('a.qa-faq-anchor').on('click', function(event) {
                    $(this).toggleClass('active');
                });
            }

    Hope that help,

    Cheers

  4. bnafz
    Member
    Posted 3 months ago #

    Hi,

    Thank you. The code worked perfectly.

    I had to make sure "Accordion behavior" was unchecked in the admin area because when the plugin automatically closes an FAQ, it kept the active class appended.

    Thanks again for the code!!

  5. Tsun4Ever
    Member
    Posted 3 months ago #

    no problem :)

    actually, a better code will be this one :

    $('a.qa-faq-anchor').on('click', function(event) {
                    if (!$(this).hasClass('active')) {
                        $('a.qa-faq-anchor.active').removeClass('active');
                    }
                    $(this).toggleClass('active');
                });

    to take in account the case where there is only one category and the case where the user is clicking on an open category.

Reply

You must log in to post.

About this Plugin

About this Topic