Using .length
to check if div with class exist and if exist .append
should not add a new div.
https://jsfiddle.net/uhvL1hfx/
HTML
<div class="container">
<div class="inner">
<div class="field">
This div exist, so .append should not add a new div, should add only if this div does not exist.
</div>
</div>
</div>
jQuery
if( $("div.container div.inner div.field").length ){
$("div.container div.inner").append("<div>But for some reason it still adds it.</div>");
}
But it still appends a new div. Should append if div.field
does not exist.