Alexsander Akers Alexsander Akers - 1 year ago 105
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?

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download