I have such a code
if ($('#bar #username').text()!=$('.widget-' + widget.id).find('.user').text())
{
//do something
}
Unfortunately, it doesn’t go through if $('.widget-' + widget.id).find('.user').text() does not exist/ underfined.
How to check if it is defined?
I’ve tried if (typeof $('.widget-' + widget.id).find('.user') === "undefined") to check whether it is defined or not, but it doesn’t help because
alert (typeof $('.widget-' + widget.id).find('.user')) shows Object,
alert (typeof $('.widget-' + widget.id).find('.user').text()) shows String.
As per the jQuery FAQ, check the
lengthproperty: