开发者

jquery files selector conflicting

开发者 https://www.devze.com 2023-04-09 18:39 出处:网络
I am using two libraries of jQuery. One is main library from site(I named it as mainlibrary.js) other as limitkeypress.js(named as same). I think both files are conflicting.I used code in sadd.php at

I am using two libraries of jQuery. One is main library from site(I named it as mainlibrary.js) other as limitkeypress.js(named as same). I think both files are conflicting. I used code in sadd.php at line 24 as

<script type="text/javascript">  
$.noConflict(); 
$(document).ready(function() {
    $("#title").limitkeypress ({ rexp:/^[A-Za-z.\-\s]*$/ });
});
</script>

I got chrome error as

  • limitkeypress.js:125 Uncaught ReferenceError: jQuery is not defined (anonymous function)

  • sadd.php:24 Uncaught 开发者_运维知识库TypeError: Property '$' of object [object DOMWindow] is not a function (anonymous function)

Where as my limitkeypress file at line 125 end with code.. })(jQuery);

Firefox extension firebug issues same error as..

  • $ is not a function

  • sadd.php(). sadd.php (line 24)

  • $(document).ready(function() {

What should I do in order avoid this error permanently. I mean if I use any other library. I won't have this error further.


You use $.noConflict(), which unbinds $, then try to use it on the next line. jQuery should be available, if you're loading jQuery.


If you are loading two versions of jquery you should have extra care because you need to use noconflict before loading the other. Look at this article an this example

<!-- load jQuery 1.1.3 -->
<script type="text/javascript" src="http://code.jquery.com/jquery-1.1.3.js"></script>
<script type="text/javascript" src="jquery.dimensions.min.js"></script>

<!-- revert global jQuery and $ variables and store jQuery in a new variable -->
<script type="text/javascript">
var jQuery_1_1_3 = $.noConflict(true);
</script>

<!-- load jQuery 1.3.2 -->
<script type="text/javascript" src="http://code.jquery.com/jquery-1.3.2.js"></script>

<!-- revert global jQuery and $ variables and store jQuery in a new variable -->
<script type="text/javascript">
var jQuery_1_3_2 = $.noConflict(true);
</script>

If you just want to use $ instead of jQuery, don't call noConflict

0

精彩评论

暂无评论...
验证码 换一张
取 消