Reputation: 1303
What does $({})
in jQuery mean ? I saw this on victmo response on this question : Possible to fade out div border?
He used $({alpha:1}).animate({alpha:0})
how this is affecting the DOM and what happens literally?
Upvotes: 5
Views: 121
Reputation: 816910
What does $({ }) in jQuery mean ?
It means "pass an empty object to jQuery
and create a jQuery object from it".
how this is affecting the DOM and what happens literally?
It doesn't affect the DOM at all, it simply changes the property value of the object {alpha:1}
over time.
You can use some jQuery methods on plain objects as explained in the documentation. Although it seems to be a bit outdated since animate
is not listed there. But it works indeed:
> $({alpha:1}).animate({alpha:0}, {step: function() { console.log(this.alpha); }})
1
0.9965342284774632
0.9870866934849247
0.9730426794137726
0.9524135262330098
0.9242551074907518
0.8926584654403724
0.8563192594626027
...
Upvotes: 6