how to pass a string into a nested function in jquery

Cesar Bielich

I am trying to figure out why I cant pass a string into a function that contains another function. I get undefined when I alert.

$.fn.downCount = function (current_time) {
    function countdown(current_time) {
        alert(current_time)
    }
})

var current_time = "01:00";
downCount(current_time);
Matthew Johnson

You never actually call the inner function. Call the function and pass in the current_time.

$.fn.downCount = function (current_time) {
    function countdown() {
        alert(current_time)
    }
    countdown();
}


var current_time = "01:00";
$.fn.downCount(current_time);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
...

Also, as Andrew mentioned, you don't need to pass in the current_time into the countdown function. It can be simplified to:

$.fn.downCount = function (current_time) {
    function countdown() {
        alert(current_time)
    }
    countdown();
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

jQuery pass function parameter to nested function

From Dev

jQuery - How to pass 'this' to a function?

From Dev

How to Pass a String in a function?

From Dev

How to call the jQuery nested function

From Dev

How to pass variable to a Jquery function

From Dev

how to pass value to a function in jquery

From Dev

How to pass variable to a Jquery function

From Dev

How to pass button into Jquery function?

From Dev

How to pass variable to a nested callback function

From Dev

How do i pass a variable to a nested function?

From Dev

How to pass a variable to javascript in nested function

From Dev

How to pass a string into a function in Python

From Dev

How to pass in variable to string with nested quotes - Ruby

From Dev

how to pass string parameter to jQuery

From Dev

Can not pass a string as function argument Jquery

From Dev

Pass a nested function as a parameter

From Dev

Pass a nested function as a parameter

From Dev

Pass arguments to nested function

From Dev

How to pass JSON string from Controller action to View and load as parameter for JQuery function

From Dev

How to get the correct nested function in jquery

From Dev

How to pass jQuery function among functions to be used as $

From Dev

How do I pass variables to a jQuery function?

From Dev

How to pass an additional argument to jQuery filter function

From Dev

Jquery ajax function how to pass variable

From Dev

how to pass an array to function in jquery jaudio

From Dev

Jquery how to pass object to another function

From Dev

How to pass jQuery function among functions to be used as $

From Dev

how to pass value in jquery function to retrieve the data

From Dev

how to pass an argument jquery and return the function value

Related Related

  1. 1

    jQuery pass function parameter to nested function

  2. 2

    jQuery - How to pass 'this' to a function?

  3. 3

    How to Pass a String in a function?

  4. 4

    How to call the jQuery nested function

  5. 5

    How to pass variable to a Jquery function

  6. 6

    how to pass value to a function in jquery

  7. 7

    How to pass variable to a Jquery function

  8. 8

    How to pass button into Jquery function?

  9. 9

    How to pass variable to a nested callback function

  10. 10

    How do i pass a variable to a nested function?

  11. 11

    How to pass a variable to javascript in nested function

  12. 12

    How to pass a string into a function in Python

  13. 13

    How to pass in variable to string with nested quotes - Ruby

  14. 14

    how to pass string parameter to jQuery

  15. 15

    Can not pass a string as function argument Jquery

  16. 16

    Pass a nested function as a parameter

  17. 17

    Pass a nested function as a parameter

  18. 18

    Pass arguments to nested function

  19. 19

    How to pass JSON string from Controller action to View and load as parameter for JQuery function

  20. 20

    How to get the correct nested function in jquery

  21. 21

    How to pass jQuery function among functions to be used as $

  22. 22

    How do I pass variables to a jQuery function?

  23. 23

    How to pass an additional argument to jQuery filter function

  24. 24

    Jquery ajax function how to pass variable

  25. 25

    how to pass an array to function in jquery jaudio

  26. 26

    Jquery how to pass object to another function

  27. 27

    How to pass jQuery function among functions to be used as $

  28. 28

    how to pass value in jquery function to retrieve the data

  29. 29

    how to pass an argument jquery and return the function value

HotTag

Archive