2014-04-21

Using JQuery with Prototype JS. How to resolve the conflict

Both JQuery and a library like Prototype JS use the $ as shortcut/alias for commands.
In order not to prevent conflict, we can change the use of $ in jQuery to some other shortcut lile $j or $jq.

This link describes how you would implement it.

http://learn.jquery.com/using-jquery-core/avoid-conflicts-other-libraries/

For quick reference, the most common case is reproduced here.

<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. $j(document).ready(function() { $j( "div" ).hide();}); // The $ variable now has the prototype meaning, // which is a shortcut for document.getElementById(). // mainDiv below is a DOM element, not a jQuery object.window.onload = function() { var mainDiv = $( "main" );} </script>

No comments:

Post a Comment

Github CoPilot Alternatives (VSCode extensions)

https://www.tabnine.com/blog/github-copilot-alternatives/