I am a beginner in JQuery.
When should the dot after $ be used?
$.trim(str)
and not $trim(str)
?
And some cases without point: $(document).ready
, but not $.(document).ready
?
Thanks.
In jQuery, the $ sign is just an alias to jQuery() , then an alias for a function. This page reports: Basic syntax is: $(selector).action() A dollar sign to define jQuery.
JavaScript provides two notations for accessing object properties. The first, and most common, is known as dot notation. Under dot notation, a property is accessed by giving the host object's name, followed by a period (or dot), followed by the property name.
The $() function The dollar function, $(), can be used as shorthand for the getElementById function. To refer to an element in the Document Object Model (DOM) of an HTML page, the usual function identifying an element is: document.
Answer: Use the jQuery delay() method You can use the jQuery delay() method to call a function after waiting for some time. Simply pass an integer value to this function to set the time interval for the delay in milliseconds.
In jQuery, $
is a variable name, like foo
or bar
, which references the global jQuery object. If you want to access a property on the jQuery object, then you use the dot. These are basically the same:
$.property jQuery.property
(Since $
is a variable like any other, it is possible for you to set it to anything you like. This might happen if you were to include the Prototype library after including the jQuery library, which would leave you with $
pointing to an alias of the document.getElementById
function.)
The jQuery object happens to also be a function, so you can call that function the same as you would call any other function:
$(arguments) alert("arguments!")
On the other hand, $trim
is just another global variable, like $
or location
, which could be a function you defined yourself:
var $trim = function(arguments) { return "foo"; }; $trim(str)
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