.not()
method removes the matching elements from the collection, $(document)
returns a collection which has only one element(the document object), you are trying to exclude an element with ID of step-4-circle
which doesn't exist in the set. Also as an object is a truthy value your condition is always true, you should use length
property as @Kevin mentions.
Also note that resize
event is fired many times, if you want to listen to this event it would be better to use .setTimeout()
function:
var t = null;
var $w = $(window).resize(function() {
clearTimeout(t);
t = setTimeout(function(){
if ( $w.width() < 768 ) {
if ($('#step-4-circle').length == 0)
$('<div id="step-4-circle">...</div>').insertBefore('#how-step-3');
} else {
$('#step-4-circle').remove();
}
}, 80);
});