Home / Web Development / Using prototype.js and jQuery together on the same web page

HowToPlaza Earn money writing

Using prototype.js and jQuery together on the same web page

by Sarah Watts

The problem with using Prototype.js and jQuery together on the same web page is that they both use the $ function differently, so there is a clash. Either Prototype can use the $ function or jQuery. But both these JavaScript libraries have great utility values if you want to develop interactive and dynamic website. With Prototype.js you can incorporate Ajax functionalities (for instance, updating contents without refreshing the entire page) and with jQuery you can dynamically resize, update and drag-and-drop various objects on the web page. So, if you can use both Prototype.js and jQuery together on the same page, it’s like, the best of both the worlds.

You can use a small function present in jQuery: jQuery.noConflict(). You can use this function to assign the attributes of the $ function to any other variable so that you can use it without any problem with Prototype. Here’s how you use it:

<script language=”javascript”>

var $jq=jQuery.noConflict();

$jq(function() {
$jq(“#thisdiv”).hide();
});

</script>

You noticed, instead of $, we use $jq (you can use any variable). And after this you can use the normal Prototype.js function as you use them.



Related posts

blog comments powered by Disqus

Previous post:

Next post: