1

thanks for having a look at this, basically I'm quite new to jQuery and what im trying to do is when the a#category-all link is clicked I want only the child links with the class "selected" to trigger a click. At the moment every a element on that level is getting clicked. Thanks for your help.

$('li a#category-all').click(function()
{
    if($(this).parent().siblings().find('a').hasClass('selected'))
    {
        $(this).parent().siblings().find('a').trigger('click');
    }
});
0

1 Answer 1

1

Assuming there are multiple <a>s, you can make this both work and work more efficiently by doing:

$(this).parent().siblings().find('a.selected').click();

As you have it, hasClass will just check if any one of the links is selected, then click all of them.

This might work, too:

$('#category-all').click(function () {
    $(this).closest('ul').find('.selected').click();
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.