As explained here, to save state which must be accessible in different events, $$(this)
is recommended, like this:
$$(this).filters = "myvalue";
What does that syntax mean? Why $$
(double dollar)? Why this
? Why the ()
(parentheses)?
That code is not working for me anyway. I must use something like:
$.filters = "myvalue";
I would like to understand why the second form is working, and the first one not.
Just check the source code of eventlly,
$$
is just a shorthand for jQuery'sdata
method:so, in a nutshell - it calls
data
on whatever jQuery returns for your argument, if there is no data attached it creates empty object, use this as newdata
and returns it.This works by assigning the value to global jQuery object, while
$$
attaches your data to object represented by query.