0

I am running following code on a link:-

$('#expertprofiles-category-filters .filterby > a').on("click", function () {
    // Figure out which category to show.
    var categoryId = $(this).attr('rel');

    // Hide the other subfilters.
    $("div.category-panel[rel!=" + categoryId + "]").slideUp(100);

    // Show the subfilters of the category.
    $("div.category-panel[rel=" + categoryId + "]").delay(100).slideDown(400);
});

This code runs fine but the problem is that I want to run this code on page load too, so that any one link is autaomatically selected.

I tried this:-

$("#expertprofiles-category-filters .filterby").find('a').trigger('click');

But it doesn't work ...

Thanks.

3
  • are you sure that $('#expertprofiles-category-filters .filterby > a') and $("#expertprofiles-category-filters .filterby").find('a') targets the same elements? Commented May 11, 2015 at 11:11
  • Yah, that's the intention. Commented May 11, 2015 at 11:16
  • 1
    Question which explained why .click() is not working with <a/> tag link. Commented May 11, 2015 at 11:18

3 Answers 3

1

You may also do the following way,

$('#expertprofiles-category-filters .filterby > a').on("click", function () {
    // Figure out which category to show.
    var categoryId = $(this).attr('rel');

    // Hide the other subfilters.
    $("div.category-panel[rel!=" + categoryId + "]").slideUp(100);

    // Show the subfilters of the category.
    $("div.category-panel[rel=" + categoryId + "]").delay(100).slideDown(400);
}).trigger("click"); // triggers click on DOM ready
Sign up to request clarification or add additional context in comments.

Comments

1

Use the same selector

$('#expertprofiles-category-filters .filterby > a').trigger('click');

Comments

0

Try this

   $('#expertprofiles-category-filters .filterby > a').click();

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.