Treehouse: Grow your CSS skills. Land your dream job.

$(document).ready() not working for jquery mobile

  • # May 28, 2013 at 7:19 pm


    i am setting up a jquery mobile site and using a jquery carousel on one of the pages.

    but document.ready() function does not work at all.

    i tried :

    – $(document).bind(‘pageinit’)

    – $(document).live(“pageinit”, function (event) {}

    but nothing seems to work on the first load, unless i do a refresh. can anyone please suggest an alternative.


    # May 28, 2013 at 7:28 pm

    Why not start off with an anonymous function?

    function init() { ... Do stuff }

    $(function() {
    # May 28, 2013 at 7:48 pm

    Can’t tell why without seeing the actual code but I guess you did something like `$(document).ready( init() )` instead of `$(document).ready( init )` (first runs the function, second references to it). You can do it like John said, but if the only thing you do in that anonymous function you might as well just do



    $(function() {
    // … Do stuff

    # May 28, 2013 at 8:10 pm

    @CrocoDillon, or EVEN:

    (function init() {
    // Do Stuff

    How long you think we can do this? lol… Anonymous functions are greatness!!!!

    # May 28, 2013 at 8:40 pm

    Haha… that doesn’t make sense! :P

    # May 28, 2013 at 8:49 pm

    @CrocoDillon, and another

    ;(function init() {
    // ... Do some more stuff

    Alright, i think i am done now!

    # May 30, 2013 at 8:28 pm

    thanks guys, i tried this stuff, but i still could not get it working, the fix was to remove the ajax page calls.

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.