$j is not a function
$j is not a function
You need to add this code to make it working (JQUERY noConflict)
var $j = $.noConflict();
This will allow you to use $j instead of $.
Why do some sites use jquery with a $j instead of just a $?
回答1
You can define, how you want to call the jquery functionality. Maybe this site uses another library, which reserves the $, and for that reason used the alias $j.
回答2
This is to avoid colision with other libraries with:
jQuery.noConflict();
For instance some libraries like prototype also use the $ sign, and if you end up using both it will most likely break. If you developed your jquery functions using $j it won't.
回答3
It's simply a method to avoid naming conflicts. Many JavaScript libraries (jQuery happens to be one of them) uses $ as a shortcut. For more information, see jQuery.noConflict()
Replace $j with JQuery
这里的做法太极端了,直接把jQuery原生代码里面修改了,这会导致其他问题。
Why we have to use $.noConflict() in jQuery?
I know we are using $.noConflict() to overcome other plugin conflicts. For example, if some new plugin use the $ symbol as a variable it will override. so, we are using like below
var $j=$.noConflict();
But, i am having doubt here, We can archive this using below code itself then why $.noConflict(); needed?
var $j=$;
Thanks advance. Kindly explain major different
回答
Here you got detailed information about why:
Many JavaScript libraries use $ as a function or variable name, just as jQuery does. In jQuery's case, $ is just an alias for jQuery, so all functionality is available without using $. If you need to use another JavaScript library alongside jQuery, return control of $ back to the other library with a call to $.noConflict(). Old references of $ are saved during jQuery initialization; noConflict() simply restores them.
It's from jQuery and there is even more information: https://api.jquery.com/jquery.noconflict/
Update after comment
From jQuery code https://code.jquery.com/jquery-1.10.2.js if you search for noConflict
you will find
noConflict: function( deep ) {
if ( window.$ === jQuery ) {
window.$ = _$;
}
if ( deep && window.jQuery === jQuery ) {
window.jQuery = _jQuery;
}
return jQuery;
},
In simple: This checks if global $
or global jQuery
has already been used. Either way it will return jQuery. So you can not just do var $j=$;
cause $
may already has conflicts. The noConflict()
is what you need.
作者:Chuck Lu GitHub |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2019-08-04 炉石兄弟 修复图腾师问题 by大神beebee102, 还有阴燃电鳗
2019-08-04 Error, DNGuard Runtime library not loaded!
2015-08-04 Net.TCP Port Sharing
2015-08-04 Hosting Multiple Service Implementations On The Same Port With WCF
2015-08-04 此集合已经采用方案 http 的地址。此集合中每个方案中最多只能包含一个地址。
2014-08-04 关于消息队列