The following script is supposed to append an element. I first check if the element exists, if not i create it and append it. The problem is that, for some reason, the checking doesn't seem to work, it keeps creating the element over and over...
Question: How to check for the existence of an element after append ?
my jsfiddle:
https://jsfiddle.net/mr54fbrL/
$(document).on("click", ".multilevel p.level", function(e) {
var box = $(this).next(".itemMenuBox"); // box you want to interact with
// if box does not exist, add it!
if( !box.length ) {
alert('not found, add it!');
var box = $("<div></div>")
.attr("class", 'itemMenuBox').text('new box')
.appendTo($(this));
} else {
alert('found box');
}
});