Grow your CSS skills. Land your dream job.

Jquery all code under $(document).ready(function()

  • # September 29, 2009 at 11:25 pm

    Ok so i know code needs to be under this:

    $(document).ready(function(){
    code for hightligning a paragraph with a particular class
    });

    $(document).ready(function(){
    code for doing animation for menu
    });

    Question if i have differnt code for different uses do i need to split it up, is there a problem if i want to split/put it together in the js file.?
    can i do it like this:

    $(document).ready(function(){
    code for hightligning a paragraph with a particular class
    code for doing animation for menu
    code for doing slider
    code for doing accordion
    });

    i’m really new to jquery so it might be a silly question.

    Rob
    # September 30, 2009 at 10:42 am

    You can :)

    # September 30, 2009 at 12:04 pm

    Yes you can do that. You might want to look into making your code a little more "object oriented" by breaking up specific tasks into objects. For example you could do:

    Code:
    var animation = function(){
    //animation code
    }

    var slider = function(){
    //slider code
    }

    var accordion = function(){
    //accordion code
    }

    var highlight = function(){
    //highlight code
    }

    $(document).ready(function(){

    var animationObj = new animation();
    var sliderObj = new slider();
    var accordionObj = new accordion();
    var highlightObj = new highlight();

    })

    This will better organize your code and as you start to develop more advanced scripts it will help you make your code run more efficiently.

    # September 30, 2009 at 12:13 pm

    Thank you ! I get it now.

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

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".