- This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
Viewing 4 posts - 1 through 4 (of 4 total)
- The forum ‘JavaScript’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › JavaScript › Jquery all code under $(document).ready(function()
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.
You can :)
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:
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.
Thank you ! I get it now.