$ target = $ (target) in javascript \ jQuery. Syntax explanation required

The sample code below is part of Keith Wood's jQuery Countdown plugin. Can someone explain this

_attachCountdown: function(target, options) {
        var $target = $(target);
        if ($target.hasClass(this.markerClassName)) {
            return;
        }
        $target.addClass(this.markerClassName);
        var inst = {options: $.extend({}, options),
            _periods: [0, 0, 0, 0, 0, 0, 0]};
        $.data(target, PROP_NAME, inst);
        this._changeCountdown(target);
    }

Is there a reason that specifically defines $ target or its just like our simple variables like var target.

Thanks in advance.

+3
source share
3 answers

This is a simple variable, $just added to tell the code reader that the jQuery collection is stored internally. Javascript is pretty "soft" with variable names, it $doesn't really matter (unlike PHP, where it is necessary before each variable name).

(var $target=$(target);) $(target) ( jQuery, target) , jQuery , .

+6

$ JavaScript .

, , ( , ) , $, , jQuery. ( , .

+2

:

var $target = $(target);

script :

$target

:

$(target)

jQuery() ($() ), target.

, , :

  • target JS (, , ),
  • $JS function (basically a function jQuery, but an alias is $often used to write shorter code)
  • $targetJS variable that stores the result of an expression $(target)(or jQuery(target))
+1
source

All Articles