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?
jQuery isEmptyObject() methodThe isEmptyObject() method is used to determine whether the passed argument is an empty object or not. It returns a Boolean value. If it finds the passed value is an empty object, it returns true. Otherwise, it returns false.
The empty() method removes all child nodes and content from the selected elements. Note: This method does not remove the element itself, or its attributes. Tip: To remove the elements without removing data and events, use the detach() method. Tip: To remove the elements and its data and events, use the remove() method.
The empty statement is a semicolon ( ; ) indicating that no statement will be executed, even if JavaScript syntax requires one. The opposite behavior, where you want multiple statements, but JavaScript only allows a single one, is possible using a block statement, which combines several statements into a single one.
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
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With