Mike Shackelford
Mike Shackelford

Reputation: 39

How do i combine 2 jquery into 1

Trying to understand this jquery and I found 2 scripts I'd like to use, but can I combine them into 1? Currently I have them both under separate script tags.

Here is the first script

$(function(){
        $('#navigation_horiz').delay(100).fadeIn(100);
        $('#navigation_horiz').naviDropDown({
        dropDownWidth: 'auto',  //the default width of drop down elements
        slideDownDuration: 600, //easing duration for slideDown
        slideUpDuration: 300 //easing duration for slideUp    
        });
});

Here is the second script

if (franchise_id==undefined) { //hide commish nav is not signed into site
     var franchise_id;
     document.write("<style type='text/css'>");
     document.write("#navigation_horiz ul li.commish { display: none; }");
     document.write("</style>");
} 
else if (franchise_id=="0000") { } //show commish nav is logged in as commish
else { // hide both if logged in as any other franchise
     document.write("<style type='text/css'>");
     document.write("#navigation_horiz ul li.commish { display: none; }");
     document.write("</style>");
}

tried to put in the same...example below and not working at all

    $(function(){
        $('#navigation_horiz').delay(100).fadeIn(100);
        $('#navigation_horiz').naviDropDown({
        dropDownWidth: 'auto',  //the default width of drop down elements
        slideDownDuration: 600, //easing duration for slideDown
        slideUpDuration: 300 //easing duration for slideUp    
        });
});
if (franchise_id==undefined) { //hide commish nav is not signed into site
     var franchise_id;
     document.write("<style type='text/css'>");
     document.write("#navigation_horiz ul li.commish { display: none; }");
     document.write("</style>");
} 
else if (franchise_id=="0000") { } //show commish nav is logged in as commish
else { // hide both if logged in as any other franchise
     document.write("<style type='text/css'>");
     document.write("#navigation_horiz ul li.commish { display: none; }");
     document.write("</style>");
}
});

Upvotes: 0

Views: 94

Answers (3)

rtexal
rtexal

Reputation: 476

A function is only executable upon well, executing it.

If you are loading the second script on first load of your website, do not put the second script into the function if you do not intend on calling the function on load.

You should only combine scripts into the same function if and only if they are serving the same event.

Upvotes: 0

Billy Chan
Billy Chan

Reputation: 24815

Yes you can. The first part is jQuery and the second part is raw Javascript, all under top namespace.

The only thing you need to note is: The jQuery code depends on jQuery lib and an independent plugin(naviDropDown?). So you must put the combined code after jQuery and the plugin.

Upvotes: 2

Raffael
Raffael

Reputation: 810

You can put them into a single tag, but it would be better to exclude them into a separate .js file and load it at the end of you document.

Upvotes: 0

Related Questions