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 8176655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:17:06+00:00 2026-06-06T23:17:06+00:00

I started to learn Jquery and but I am having trouble understanding function parameters:(

  • 0

I started to learn Jquery and but I am having trouble understanding function parameters:(
If you look my first code and run it: my script WILL work (WITHOUT parameters). And if you look my second code
(WITH parameters) and run it: second script WILL ALSO WORK!!

My first question: Did I correctly set parameter in my second script?
Second question: How can I check is my parameter set or being passed correctly to my function?

P.S. Sorry for being NOOB and THANK YOU!!

   //First code (WITHOUT PARAMETERS!!!) 
   $(document).ready(function () {
       var addclass = $('p:first');

       function AddClass() {
           addclass.addClass('first');
           if (addclass.is($('.first'))) {
               alert('here');
           }
           else {
               alert('not here');
           }
       }
       $('.button').click(function () {
           AddClass(addclass);
       });
   });
   //Second code (WITH PARAMETERS)
   $(document).ready(function () {
       var addclass = $('p:first');

       function AddClass(addclass) {
           addclass.addClass('first');
           if (addclass.is($('.first'))) {
               alert('here');
           }
           else {
               alert('not here');
           }
       }
       $('.button').click(function () {
           AddClass(addclass);
       });
   });
  • 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-06T23:17:07+00:00Added an answer on June 6, 2026 at 11:17 pm

    your second arguments is right and to check any arguments passed to a function use:

    arguments.length
    

    for example:

    function myfunc() {
       alert( arguments.length ); //output: 1, because you passed one argument
    
       // and to get that
    
       var myarg = arguments[0];
    }
    
    myfunc(someVar);
    

    If you don’t pass any arguments then:

    function myfunc() {
       alert( arguments.length ); //output: 0, because you passed no argument
    }
    
    myfunc();
    

    For your function:

      function AddClass(addclass) {
    
                          ^-- declaring addclass is not necessary if you use like following
    
           // checking for argument
    
           if( arguments.length ) {
             // arguments[0] will give you addclass
             // you may not write addclass to function like above
           }
    
           addclass.addClass('first');
           if (addclass.is($('.first'))) {
               alert('here');
           }
           else {
               alert('not here');
           }
       }
    

    Call function with addclass arguments:

       $('.button').click(function () {
           AddClass(addclass);
       });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I started to learn jQuery. I wrote a code, that will cycle the position
jQuery(function ($) {..} I am trying to learn jQuery and came across some code
Ok guys, I started to learn more about Jquery and now I could make
I have just started to learn how to code iOS apps. I have made
I have started to learn about python and is currently reading through a script
I started to learn using Instrument, but I cannot figure it out. After I
I've finally started to learn PHP and I quite have trouble with it. I
i just started to learn coffeescript and it's great, but it's tricky.. i try
Still trying to learn the basic of jquery so in the weekend I started
I started learn GWT by example on google and my first conclusion is: too

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.