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

  • Home
  • SEARCH
  • 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 8867927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:09:06+00:00 2026-06-14T17:09:06+00:00

Basically the Title states the question, but the situation is this (it’s difficult to

  • 0

Basically the Title states the question, but the situation is this (it’s difficult to replicate with jsbin or anything else, so I’m going to try to solve without doing that).

I have a function that is called on the click of a button. The click event will tell the output what font will be used. However, on certain pages, I want the font to be declared by the class of the body element and not on the click of a button.

I’m running into two problems.

  1. When I try to pass an argument and receive a parameter, the parameter is an event, rather than whatever I want to pass.
  2. If I pass the event as the first parameter and the font I want as the second, I get undefined as my font variable and the function does not work.

Any help on making a function be flexible in this way would help me out a lot.

Edit: Here’s a simplified version of what I’ve got

function fontSelection(font) {

var self = $(this),
  inputOne = $('li:eq(0) input').val(),
  inputTwo = $('li:eq(1) input').val(),
  inputThree = $('li:eq(2) input').val(),
  resultOne = $('div:eq(0)'),
  resultTwo = $('div:eq(1)'),
  resultThree = $('div:eq(2)');
  font = font || $('div.font').attr('title').toLowerCase();

resultOne.removeClass().addClass(inputOne + ' someclass ' + font);
resultTwo.removeClass().addClass(inputTwo + ' someclass ' + font);
resultThree.removeClass().addClass(inputThree + ' someclass ' + font);

}
  • 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-06-14T17:09:07+00:00Added an answer on June 14, 2026 at 5:09 pm

    Rather than pass your function directly to the event registration, you pass an anonymous function that then calls your function with the desired arguments.

    So, rather than this:

    $("#myButton").click(callMyFunction);
    

    You use this which allows you to specify the exact arguments you want:

    $("#myButton").click(function(e) {
        callMyFunction(myParam1, myParam2);
    });
    

    If you want to preserve, the value of this in your function, then you need to use .call() like this to explicitly set it appropriately in your function:

    $("#myButton").click(function(e) {
        fontSelection.call(this, myParam1, myParam2);
    });
    

    Or, just pass it as an argument and use the argument in your function instead of this:

    $("#myButton").click(function(e) {
        fontSelection(this, myParam1, myParam2);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is as simple as the title states. It's probably been asked hundreds
Apologies for the very broadly title question. Basically this follows on from my earlier
The title is pretty self explanatory, but basically I need the table row to
The title pretty much says it all, but basically I have a main parent
Maybe the title could be rephrased slightly better but basically I'm wondering how the
I hope the title is chosen well enough to ask this question. Feel free
Ok, so the title is a bit convoluted. This is basically a greatest-n-per-group type
I hope the title of this question is somewhat clear, I couldn't figure out
I will have to admit the title of this question sucks... I couldn't get
Yes, this is probably yet another greatest-n-per-group question... But I've tried at least a

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.