Let's say we have:
var $letsTestA = $( '.lets-test-a' ),
$letsTestB = $( '.lets-test-b' );
While the HTML is:
<div class="lets-test-a"></div>
(I know, I left out .lets-test-b)
Now, what happens if we try to call the variable $letsTestB?
I did do some testing, I'm not just blindly asking a question without doing some research first, but I'm a little confused with how this seems to work...
If I alert($letsTestA); or alert($letsTestB); I get the same outcome which is just [object Object] when testing from JSFiddle?
Here's my test fiddle: https://jsfiddle.net/m6j03423/
Furthermore to this, what I'm actually trying to do here is create a way to find out whether the content of a variable exists or not.
In PHP I would just write if (empty($myVar)) { // do action } but JS doesn't work the same way.
In JS I think I can write if ($letsTestA) { } and it should be able to print the result of the variable? But, I'm still getting [object Object].
What am I missing?
Can I even print the contents of a jQuery object?
How can I test whether the variable contains the true value of a jQuery object?
EDIT: Admittedly, I did see a few different answers saying to check the length, but I didn't understand that enough to connect that to what I'm doing.
lengthproperty. If you haven't already I'd strongly suggest you read some of the jQuery user guides at learn.jquery.comalert()is confirming that. What's in that object, you're not examining. Debug the code. If you want to know what's in those variables, pause execution at that point and examine the runtime values of those variables.