Friday, October 15, 2010

Dollar Sign function in JS

I have seen function like $("myid") in a number of javascript libraries. It worked fine for most browsers. JQuery, Prototype etc all uses this type of function name or name prefixed with $ sign. By itself it is no big deal. However, you cannot mix different libraries that uses functions that has $ signs or function names that prefixed with $. Inevitably, you may come across with functions with the same names across different libraries.

The following is a basic example of the use of $ function.

function $(idname){
return document.getElementById(idname)
}

var mytext=$("myid").innerHTML

Many Javascript Libraries have much more elaborate functionalities using this type function name.

No comments:

Post a Comment