• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 245
  • Last Modified:

Javscript $

I have a function called

function $(elementId){

what does the symbol $ mean?  is that the name of my function?

0
gazdzid
Asked:
gazdzid
3 Solutions
 
leakim971PluritechnicianCommented:
0
 
Richard QuadlingSenior Software DeverloperCommented:
"Is that the name of my function?"

Yes.

Many of the popular javascript libraries use $ or $$ to represent a function to access any element within the DOM by either its ID or via CSS rules.

http://api.prototypejs.org/dom/dollar.html
http://api.prototypejs.org/dom/dollardollar.html
http://docs.jquery.com/API/1.3/Core 
etc.
0
 
kadabaCommented:
To put in simple terms its just another identifier/ function name
There are certain rules and naming conventions generally followed for variable names, function names etc in javascript as in any other language for that matter.

Now question would be how does this function help?
Instead of doing document.getElementById() each time to access an object this will be a short hand representation of the same. Now the advantage would be that we will be able to use this as its simple.

Generally this concept is used by powerful javascript frameworks like jquery etc. where this conept is also used to get the elements by name and class.

Remember that when you are not using such javascript frameworks you can safely use this function but when the javascript frameworks kicks in its better to avoid the usage of this function( and if you still want to use you can modify the jquery framework etc to make it work using settings in the framework). When you are not using such frameworks you can use it without any concern for easy usage.

Hope that clears your point.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
gazdzidAuthor Commented:
Thank you for your inputs!!
0
 
leakim971PluritechnicianCommented:
Thanks for the points!
0
 
Richard QuadlingSenior Software DeverloperCommented:
Ditto.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now