1

One of the scripts added in between the <head> element kills my other javascript. Is their a way to isolate it or not to interfere with other scripts? I need this only for one page, not for the whole site ,etc. frontpage.php. Tried to add the script only to this page, but it dont work, as it seems what it only works than I put in between <head></head> elements.

This is the killer script:

<script type="text/javascript">
    $(document).ready(function() { 
        $.noConflict();

        <!-- THE ACTIVATION OF THE MINI IMAGE SLIDER PLUGIN -->
        jQuery('#first_mini_slider').minislides(
        {                                       
            width:980,
            height:320,                         
            slides:5,
            padding:30,
            ease:'easeOutQuint',
            speed:400,
            hidetoolbar:2000,
            animtype:1,
            mousewheel:'on'
        })

        <!-- THE ACTIVATION OF THE LIGHTBOX PLUGIN -->
        jQuery('.freshlightbox').fhboxer({})
        jQuery('.freshlightbox_round').fhboxer({
            hover_round:"true"
        })
    });
</script>
CAbbott
  • 8,078
  • 4
  • 31
  • 38
  • 1
    First of all: What error are you getting? To answer your question, putting the code in a try-catch block catches non-fatal errors: `try{/*code here*/}catch(e){}`. – Rob W Jan 25 '12 at 16:47

1 Answers1

3

The script you posted puts jQuery into "noConflict" mode, which means that the $ used to refer to jQuery will no longer work. You can still refer to jQuery with jQuery i.e. these two are equivilent:

$('.freshlightbox')

jQuery('.freshlightbox')

If this is what is causing problems with your other scripts you can do one of the following:

  1. don't put jQuery into noConflict mode
  2. change your other scripts to use jQuery instead of $
  3. put the following code around your other scripts:
 (function($){
 // your code goes here
  })(jQuery);

more detail on the last here: https://stackoverflow.com/a/4484317/12744

Community
  • 1
  • 1
Colin Pickard
  • 45,724
  • 13
  • 98
  • 148