Alexsander Akers Alexsander Akers - 4 months ago 24
Javascript Question

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

What's the difference between

var $x
var x
in javascript?


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