jQuery conflict between scripts
I am using CakePHP and am using 2 javascript scripts one of which relies on jQuery.
On one of these javascripts the $ variable is used which conflicts with jQuery and thus
I had to include the following bit of code in cakephp :
<?php
$this->Js->JqueryEngine->jQueryObject = '$j';
print $this->Html->scriptB开发者_开发百科lock('var $j = jQuery.noConflict();', array('inline' => false));
?>
This made the javascript + jQuery inclusion work fine. I then wanted to add another javascript which requires jQuery - which I have however I get the following error:
Uncaught TypeError: Object function $(element) { if (arguments.length > 1) {
for (var i = 0, elements = [], length = arguments.length; i < length; i++)
elements.push($(arguments[i]));
return elements; } if (Object.isString(element))
element = document.getElementById(element); return Element.extend(element);} has no method 'extend'
I am not a massive javascript buff. But this confuses me and obviously there is a conflict - please help me get this jQuery based script work.
Thanks,
You need to use the no conflict selector that you defined in the no-conflict section, i.e. $j instead of simply $.
精彩评论