tags:

views:

110

answers:

4

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?

+5  A: 

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.

marcgg
In the case of this site, they probably say $j = jQuery.noConflict(); - then $j is available as the $ from jQuery, and the previous meaning of $ (if any) is overwritten.
jnylen
+6  A: 

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.

janoliver
good to know, can you just "do it" or do you need to define it/set it somewhere else?
jasondavis
http://docs.jquery.com/Using_jQuery_with_Other_Libraries#Overriding_the_.24-function
janoliver
`$j = jQuery.noConflict();`
gnarf
+3  A: 

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()

carl
+1  A: 

Its definitely to avoid collision with other libraries. The most notorious of which would be prototype and scriptaculous.

Daniel
also mootools. :)
janoliver