I need to add a child selector and child element to a variable, referencing an element.
but i can’t seem to get it working..
I’ve tried;
var wrapper = $('#wrapper');
if($(wrapper+' > .box').length > 0)) // unsuccessful
if(wrapper.add(' > .box').length > 0)) // unsuccessful
and
if(wrapper[0]+' > .box'.length > 0)) // unsuccessful
thanks cam
The issue is that you’re confusing the selection with the selector. If you were to have done:
Then you could test it appropriately:
Note that
>is the first-child selector.