4

I have a problem with the returning value of the test function. This is the code:

$(document).ready(function () {
    $("p").hide( test );

    function test() {
            return 5000;
    }
});

After a bit of research a found the parseInt() function. But it didn't work.

  1. try with parseInt():
        $(document).ready(function () {
            $("p").hide( test );
    
            function test() {
                return parseInt(5000, 10);
            }
        });
        
  2. try with parseInt():
        $(document).ready(function () {
            $("p").hide( parseInt(test, 10) );
    
            function test() {
                return 5000;
            }
        });
        

I know I could just type:

$("p").hide( 5000 );

But that function will get more complex after resolving this problem.

1
  • What you pass into into hide() is the function test, not the result of test(). jQuery interprets this as a completion callback - "call test after hiding the element". Commented Feb 16, 2013 at 16:53

1 Answer 1

4

You are not executing the function:

$(document).ready(function () {
    $("p").hide( test() );  // note the additional ()

 function test() {
  return 5000;
 }
});
Sign up to request clarification or add additional context in comments.

2 Comments

+1. But also tell him that without () was for assigning function (which will not work in this case) and with () it will execute.
:D I just can't believe I forgot those. Thank you very much.

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.