Use of $j in javascript

Pragya8
Kilo Contributor

I was wondering what the $J means in this javascript excerpt?

 $j('title').html("${gs.getMessage('Create Article Translation')}");

$j('div.editable-html-field').find('div[id ^=kbblock][id $=kbblock]').each(function()

$j('div.editable-html-field').find('div[id ^=kbblock][id $=kbblock]').removeAttr('contenteditable');

1 ACCEPTED SOLUTION

Gaurav Shirsat
Mega Sage

Hi

Happy New Year

The dollar sign is commonly used as a shortcut to the function document.getElementById(). Because this function is fairly verbose and used frequently in JavaScript, the $ has long been used as its alias, and many of the libraries available for use with JavaScript create a $() function that references an element from the DOM if you pass it the id of that element.

There is nothing about $ that requires it to be used this way, however. But it has been the convention, although there is nothing in the language to enforce it.

The dollar sign $ was chosen for the function name by the first of these libraries because it is a short one-character word, and $ was least likely to be used by itself as a function name and therefore the least likely to clash with other code in the page.

Now multiple libraries are providing their own version of the $() function, so many now provide the option to turn off that definition in order to avoid clashes. 

Of course, you don't need to use a library to be able to use $(). All you need to substitute $() for document.getElementById() is to add a definition of the $() function to your code as follows:

function $(x) {return document.getElementById(x);}

The $ represents the jQuery Function, and is actually a shorthand alias for jQuery. (Unlike in most languages, the $ symbol is not reserved, and may be used as a variable name.) It is typically used as a selector (i.e. a function that returns a set of elements found in the DOM).

 Please Refer

https://stackoverflow.com/questions/1150381/what-is-the-meaning-of-sign-in-javascript#:~:text=The%20...

Please Mark Correct and Helpful

Thanks and Regards

Gaurav Shirsat

View solution in original post

3 REPLIES 3

MrMuhammad
Giga Sage

$j is a jQuery object. jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers.

See jQuery Doc for reference - https://jquery.com/

Hope that helps!

 

Regards,
Muhammad

Ho do i change the ui action color on load of a form 

 

Gaurav Shirsat
Mega Sage

Hi

Happy New Year

The dollar sign is commonly used as a shortcut to the function document.getElementById(). Because this function is fairly verbose and used frequently in JavaScript, the $ has long been used as its alias, and many of the libraries available for use with JavaScript create a $() function that references an element from the DOM if you pass it the id of that element.

There is nothing about $ that requires it to be used this way, however. But it has been the convention, although there is nothing in the language to enforce it.

The dollar sign $ was chosen for the function name by the first of these libraries because it is a short one-character word, and $ was least likely to be used by itself as a function name and therefore the least likely to clash with other code in the page.

Now multiple libraries are providing their own version of the $() function, so many now provide the option to turn off that definition in order to avoid clashes. 

Of course, you don't need to use a library to be able to use $(). All you need to substitute $() for document.getElementById() is to add a definition of the $() function to your code as follows:

function $(x) {return document.getElementById(x);}

The $ represents the jQuery Function, and is actually a shorthand alias for jQuery. (Unlike in most languages, the $ symbol is not reserved, and may be used as a variable name.) It is typically used as a selector (i.e. a function that returns a set of elements found in the DOM).

 Please Refer

https://stackoverflow.com/questions/1150381/what-is-the-meaning-of-sign-in-javascript#:~:text=The%20...

Please Mark Correct and Helpful

Thanks and Regards

Gaurav Shirsat