Home Blog JavaScript TypeError: $(...).newsTicker is not a function
TypeError: $(...).newsTicker is not a function
JavaScript
Written by Dicky   
Monday, 27 January 2014 17:52
AddThis Social Bookmark Button

I tried to call an extended jQuery function inside a  $(document).ready(function () {.

The code is as follow:

 $(document).ready(function ($) {

                $.ajax({
                    type: "GET",
                    url: API_URL,
                    dataType: "xml",
                    success: function (xml) {
                        $(xml).find('News').each(function () {
                            .....
                        });
                    },
                    error: function (xhr) {
                        alert(xhr.responseText);
                    }
                });

                $('#newsList').newsTicker();
            });

However, for some reason the $('#newsList').newsTicker(); never get executed and I cannot figure it out why. Upon doing more research and looking at the error message provided by the built-in Javascript console on Firefox, I realized that the $() function inside the $(document).ready() is not recognized. To fix it, I simply need to change it to $(document).ready(function($) {. By providing the $ inside the function(), it decalares that the $() function is still in use. That small change fix my problem immediately.