What's the difference between ‘var $x’ and ‘var x’ in javascript?

javascript, variables

Solution

Nothing. People tend to use the $x syntax because it's easier to remember you're dealing with a jquery object rather than an element or an id.

In general I tend to use something similar to:

var $x = $(selector) //$x holds reference to a jquery object
var elX = document.getElementById(id); // elX hold ref to an element node
var xId = $(selector).attr('id'); //xId holds ref to an id attribute

Problem

What's the difference between `var $x` and `var x` in javascript?

Original source

Related problems