What does the $ before the function mean in Javascript? I found this in a Javascript script for a Chromium extension.
$(function() {
$('#search').change(function() {
$('#bookmarks').empty();
dumpBookmarks($('#search').val());
});
});
What does the $ before the function mean in Javascript? I found this in a Javascript script for a Chromium extension.
$(function() {
$('#search').change(function() {
$('#bookmarks').empty();
dumpBookmarks($('#search').val());
});
});
This looks like jQuery but could also be any number of web frameworks.
$ is simply a variable (in this case a function) name, just like any other JavaScript variable name. It likely is also available and aliased as jQuery.
You can confirm and see the version using the below in a browser's developer console while on the website.
$ === jQuery
> true
$.fn.jquery
> "1.12.1"
This could be an Immediately-invoked Function Expressions with jQuery. $ is equal to 'jQuery'. With the immediate function, you can define variables inside the context of the function and avoid global variable definitions. As soon as jQuery loads this function executes.