Html, css and javascript syntax use of $ char

Html, css and javascript syntax use of $ char


I just started the API, AJAX and JSON section on FCC and they have suddenly started using a $ infront of code why? what does it do?


The dollar sign is there because some of those functions are from jQuery, which is what is called a “library” - a collection of functions/mini-programs that you tap into by using the $ sign to identify them. You’ll get to like that dollar sign because jQuery saves you a lot of time.


In native JavaScript, nothing in particular. If the jQuery library is added, it’s usually used as an alias for the jQuery namespace. So for example, $.ajax() is just a quicker way of writing jQuery.ajax().

One very common use of it with jQuery is to convert DOM objects into jQuery objects, which allows you to use jQuery methods on them. For example, you can write something like this:

$('#myInputField').val('Hello World!');

This has the same effect as the native JavaScript:

document.querySelector('#myInputField').value = 'Hello World!';

Similarly, there are some jQuery methods that would be more complex to implement in pure JavaScript, such as:


This creates a fade out animation on that element with a duration of 1000 milliseconds.

More info: