WordPress.org

Support

Active or current class

  • 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/

Viewing 4 replies - 1 through 4 (of 4 total)
  • 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.

    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

    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!!

    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.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Active or current class’ is closed to new replies.
Skip to toolbar