Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
477 views
in Technique[技术] by (71.8m points)

What is the difference between $ and jQuery

When I try to use $("#div_id") in $(document).ready it returns NULL, but when I use jQuery("#div_id") it returns the actual object!

Why is that happening?

UPDATE: I tried noConflict method without gaining any hints.

jQuery.noConflict()
function (a,b){return new c.fn.init(a,b)}

$.noConflict();
TypeError: Object function ()
    {
        return document.getElementById.apply(document, arguments)
    } has no method 'noConflict'

UPDATE 2:

$(document).ready(function() {
    debugger;
});

<input type="text" id="test" name="test" value="123" />

When I run the following code in the console i got those results:

$("#test").val()
TypeError: Cannot call method 'val' of null
jQuery("#test").val()
"123"

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

See jQuery.noConflict(). Could other javascript libraries on your page be using the $ variable?

$ is just a variable that is used to alias jQuery and being a variable, anything could be assigned to it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...