Possible Duplicate:
Can someone explain the dollar sign in Javascript?
Why do certain javascript functions have a $ before the function delcaration?
For example, here’s the javascript for a JQuery slider. The source code can be found here http://jqueryui.com/slider/#rangemin
<script>
$(function() {
$( "#slider-range-min" ).slider({
range: "min",
value: 37,
min: 1,
max: 700,
slide: function( event, ui ) {
$( "#amount" ).val( "$" + ui.value );
}
});
$( "#amount" ).val( "$" + $( "#slider-range-min" ).slider( "value" ) );
});
</script>
The
$isn’t a JavaScript thing, it’s just a shortcut used by jQuery.$is a valid identifier name in JavaScript, and it’s short, so it was popular with libraries (jQuery, Prototype, and probably a couple of others used it).$is just an alias for the symboljQuery.The code you’ve quoted there is calling the
$function and passing in a function reference (in this case, for a function defined inline). When you pass a function reference into$(orjQuery), you’re asking the jQuery library to run that function when the DOM is ready. It’s a shortcut for$(document).ready(...). Details in the documentation.