Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do some sites use jquery with a $j instead of just a $?

Tags:

jquery

I generally use this in jquery

$(document).ready(function() {
    //stuff
}

I was just on a site that heavily uses jquery and they call it using

$j(document).ready(function() {
    //stuff
}

On this site they start almost everything out with a j...

function PostComment(form) {
  form = $j(form);
  $j('#CommentSubmitButton').hide();
  $j('#CommentInProgress').show();
  $j.post('/utils/ajaxhandler.aspx', form.serialize(), function(data) {
    $j('#CommentInProgress').hide();
    $j('#CommentSubmitButton').show();
  });
}

Is this just another way of doing it or is this dependent on a differnt version of jquery or other?

like image 296
JasonDavis Avatar asked Sep 07 '09 23:09

JasonDavis


People also ask

What is $j in jQuery?

The $ represents the jQuery Function, and is actually a shorthand alias for jQuery .

Why jQuery noConflict () method is being used?

noConflict() method to give control of the $ variable back to whichever library first implemented it. This helps us to make sure that jQuery doesn't conflict with the $ object of other libraries. // Import other Library // Import jQuery Library $. noConflict(); // Code that uses other library's $ can follow here.

What does $() mean in jQuery?

In jQuery, the $ sign is just an alias to jQuery() , then an alias for a function. This page reports: Basic syntax is: $(selector).action() A dollar sign to define jQuery. A (selector) to "query (or find)" HTML elements.

What does jQuery noConflict meaning?

Definition and Usage The noConflict() method releases jQuery's control of the $ variable. This method can also be used to specify a new custom name for the jQuery variable. Tip: This method is useful when other JavaScript libraries use the $ for their functions.


2 Answers

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.

like image 74
janoliver Avatar answered Nov 16 '22 02:11

janoliver


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.

like image 40
marcgg Avatar answered Nov 16 '22 01:11

marcgg