You couldn’t use just find
in if
condition. You could use has
or check for the length
property.
var elm = $('.parent1');
if(elm.has('.child3')){
var child3 = elm.find('.child3');
}
Or simply like this
var child3 = $('.parent1').find(".child3");
if(child3.length > 0) {
// child3 is present
}