Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6956869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:55:31+00:00 2026-05-27T14:55:31+00:00

Supposing I have the line of code: $comparePanel.on(‘click’, ‘.pills li:not(.active)’, toggleComparisonPanel); Pointing to the

  • 0

Supposing I have the line of code:

$comparePanel.on('click', '.pills li:not(.active)', toggleComparisonPanel);

Pointing to the function:

function toggleComparisonPanel() {
  event.preventDefault();
  $(this).addClass('active').siblings().removeClass('active');
  $quickSpecsTable.toggleClass('comparison-mode');    
  $filters.toggle();
}

This works in Chrome as apparently it attaches event to window making it global as I understand it. However Firefox requires the event to be passed to the function. I’ve tried this with no success:

$comparePanel.on('click', '.pills li:not(.active)', toggleComparisonPanel(event);

function toggleComparisonPanel(event) {
  event.preventDefault();
  $(this).addClass('active').siblings().removeClass('active');
  $quickSpecsTable.toggleClass('comparison-mode');    
  $filters.toggle();
}

Is something like this even possible, or is my only option to put the code into an anonymous function within the .on() function, something like the following code?

$comparePanel.on('click', '.pills li:not(.active)', function(event){
  event.preventDefault();
  $(this).addClass('active').siblings().removeClass('active');
  $quickSpecsTable.toggleClass('comparison-mode');    
  $filters.toggle();
});

I’d prefer to keep my event handler and the function separate if at all possible. Probably not much reason other than it feels tidier to me to be honest, but it’d be nice to do it

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:55:32+00:00Added an answer on May 27, 2026 at 2:55 pm

    You can simply declare the function somewhere else, like this:

    // declare event here, since you're using it here    
    function toggleComparisonPanel(event) {
        event.preventDefault();
        $(this).addClass('active').siblings().removeClass('active');
        $quickSpecsTable.toggleClass('comparison-mode');    
        $filters.toggle();
    }
    
    
    //                                                  just pass the function here
    $comparePanel.on('click', '.pills li:not(.active)', toggleComparisonPanel);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Supposing I have the C# code line: var myList = new List {1,2,3}; And
Supposing I have some random block of text in a single line. Like so
Supposing I have a function with following signature: Foo[] getSomeFoos() { //return null ---
Supposing to have something like this: #include <map> int main(){ std::map<int,int> m; m[1] =
Supposing I have one perl in /usr/bin (which came along with my os-distribution) and
Supposing I have this: foo bar 1 and foo bar 2 How can I
MVC newbie question re binders. Supposing I have two strongly typed partial actions that
What's the object type returned by Datepicker? Supposing I have the following: $(#txtbox).datepicker({ onClose:
Supposing that I have millions of user profiles, with hundreds of fields (name, gender,
I have to detect port aggregation configuration on Linux. Supposing that the ifcfg-* files

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.