How can I prevent a JavaScript file from conflicting with another? -


i have 2 scripts running on site developing , 1 conflicting other

the second 1 work if first 1 missing.so don't know problem is.

you can see link.

http://electionsguru.in/mfc_new/newkursplan.php?id_shop=35

in page having preview title on 3rd section,in part if click on title light box appear left menu drop down script not work , conflicting light box script.

depending on how large script is, using namespace typically way eliminate conflicts.

the 2 common ways introduce are:

var ns = ns || {}; ns.ondocready = function(){/*your declaration here*/}; ns.onsomeotherfunct = function(arg){/*your declaration here*/}; 

or

var othernamespace = {   publicvar:'something available namespaced functions',   ondocready:function(){/*your declaration here*/},   someotherfunction:function(arg){/*your declaration here*/} }; 

then call functions within named object (e.g. namespace)

ns.ondocready(); othernamespace.someotherfunction('test'); othernamespace.publicvar = 'available functions within namespace referencing "this" keyword'; 

the caveat remember when using "this" keyword reference variable or functions within object, may conflict jquery "this" keyword. avoid, set variable within function.

var ns1 = {   islive : false,   docheck : function(){     var ns = this; //--set scope variable access prevent conflict within jquery functions keyword referenced     if(this.islive){/*conditional declaration*/};   } } 

Comments