1

Situation:

  • On a single webpage I am using Syntax Highlighter and Lightbox 2
  • Syntax Highlighter uses JavaScript. Lightbox 2 uses jQuery (version 1.7.2)
  • When I run each of the scripts on independently(different pages), it works
  • Problem only occurs when I run both on the same page
  • On Google Chrome, web page runs perfectly
  • On IE 8 I get an error when a part of the lightbox2 function is called
  • Error points to jquery1.7.2 file stating method/property not supported by this object
  • Code for the exact line of error is: parts = rfxnum.exec(val);
  • I inserted an alert() to show me vlaues for both rfxnum and val
  • rfxnum=/^([+-]=)?([\d+.-]+)([a-z%]*)$/i
  • val = 802
  • The crazy thing I discovered is that when I run the two scripts independently the alert shows identical values for rfxnum and val, and yet it runs fine.
  • Syntax Highlighter runs fine in all conditions

My Guess: -Syntax Highlighter seems to be interfering w/ values/functions/parameters in jQuery 1.7.2 library. OR some global value that both syntax highlighter and jQuery library reference.

My Question:

  • Is there a way to prevent Syntax Highlighter or any other non-jQuery JS script to NOT interact/reference the jQuery lib.
  • If the answer is, JavaScript won't reference jQuery libs in the first place, then my question is what are some possible reasons that something like this occurs.
  • Alternatively, is there a way to package the jQuery lib and relevant JS functions together so that no other functions could reference any of the functions/variables in the package

I would appreciate any suggestions/insights.

2
  • 2
    If possible please make a sample in jsbin.com so that others will get a better idea. Commented Jun 28, 2013 at 7:38
  • 1
    Can try to wrap "no jquery code" with self invoking anonymous function (function() { .. })(); and/or use jquery noconflict $.noConflict(); jQuery(document).ready(function($) { // Code that uses jQuery's $ can follow here. }); Commented Jun 28, 2013 at 7:41

1 Answer 1

2

You can use noConflict()

<!-- Putting jQuery into no-conflict mode. -->
<script src="prototype.js"></script>
<script src="jquery.js"></script>
<script>

var $j = jQuery.noConflict();
// $j is now an alias to the jQuery function; creating the new alias is optional.

Using jQuery.noConflict(); - Lightbox and jQuery conflict

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the reply. I have read about noconflict before but i still have trouble understaning how to actually use it. In my above situation, do i go and replace every single $ with $j? or do i put $j infront of all my functions? ($j.function(){.
Its clearly there in the first link..seee second paraghraph ..use like jQuery.noConflict(); jQuery( document ).ready(function( $ ) {
Sincere apologies, first time at this form and didn't notice the link under the code example. I've gone through everything in the link you gave me, tried everything i could w/ no conflict. Conclusion is i dont think its noconflict issue. A)All attempts failed w/ noconflict B) Most of the posts on the link you have provided disscusses jquery vs jquery. This case is js(non-jquery) vs jquery and no use of $ in the js script. C) why work in google chrome at all if it were a noconflict problem. Either way thanks for your advise, helped me understand a bit more about no conflict.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.