Alexsander Akers Alexsander Akers - 1 month ago 9
Javascript Question

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

What's the difference between

var $x
and
var x
in javascript?

Answer

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
Comments