Ok so basically I need to check,whether in my menu #Container exist any third level elements (h3 to be exact) and if yes give them some attribute. If not give this attribute to second level element (h2) which always exists. Is :
if ($('h3')) {
//some attribute
} else {
//some attribute
};
the right method ?
Use .length for this, it’s 0/false if there aren’t any matches:
Short version, less readable: