In jQuery, if I do this:
var a = $("#someid");
Now when I need to further reference using jQuery, what should I be doing?
$(a).attr("id");
or
a.attr("id");
I'm testing things out and I'm getting confused, just want the official word so I can rule this out.
This one:
a.attr("id");
since a
is already a jQuery object.
Although it is a convention used by many to prefix variables that reference a jQuery object with $
.
So:
var $a = $("#someid");
$a.attr("id");
This is only a common convention, and not a requirement. I think it adds clarity, but that may be just because I'm pretty conditioned to look for the $
by now.
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