If my html is as like below
<div id="TestHash"> </div>
I can access it as $("#TestHash")
, $(TestHash)
. Both will result the same.
what is the usage of element without # ??
Definition of necessity 1 : the quality or state of being necessary He questioned the necessity for the change. 2a : pressure of circumstance The plane was compelled by necessity to change its course. b : physical or moral compulsion did it, not because he wanted to, but by necessity.
The definition of a necessity is something that is absolutely needed. An example of a necessity is water for life. Something necessary. The necessities of life include food, clothing, and shelter.
1[uncountable] the fact that something must happen or be done; the need for something necessity (for something) We recognize the necessity for a written agreement.
In fact, there is a legacy artefact in Javascript - elements with an ID automatically populate global namespace.
This is why you can access it directly the way you are ($(TestHash)
). However, it's a misunderstood piece left over from legacy browsers, so you shouldn't rely on it.
Where possible, always use the $("#myId")
version.
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