Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is basic difference between $ Vs JQuery

Tags:

jquery

I have a js file which has several fn() and it was working fine but when at tached a js plugin file, i get error in firebug.

$(document).ready(function() {
     var innerHTML = $("#id_1").html();
     $("#Id_2").html(innerHTML)    
   });

above fn() was working but now i am getting error in firebug $("#id_1") is null.

if i use jQuery instead of $ then it's workin fine. please see below the corrected function.

$(document).ready(function() {
     var innerHTML = jQuery("#id_1").html();
     jQuery("#Id_2").html(innerHTML)    
   });

now my problem is, i have several js files and i have used $ and now i might have to change $ to jQuery. please give me any idea to avoid this.

like image 866
user1010399 Avatar asked Dec 07 '25 03:12

user1010399


2 Answers

The extra library you are using (wysiwyg.js) is also declaring a function $():

/**
 * Get an element by it's identifier
 *
 * @param id Element identifier
 */
function $(id) {
    return document.getElementById(id);
}

You should use jQuery.noConflict()

like image 187
Didier Ghys Avatar answered Dec 11 '25 23:12

Didier Ghys


$ is just an alias for 'jQuery' . Please make sure the library you are adding is not making any conflict with '$' . It generally happens when you try adding another framework with '$' as alias ex prototype.

use jQuery no Conflict http://api.jquery.com/jQuery.noConflict

like image 24
Gaurav Shah Avatar answered Dec 11 '25 23:12

Gaurav Shah



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!