I'm trying to write a helper function for jQuery that creates an element if it doesn't already exist. So far I have:
function setup(element, parent){
if($(parent).child(element).length == 0){
$(parent).append('<div class="'+element+'"></div>');
}
}
but I'm wondering if this isn't a solved problem. Is it?
(The reason I want this is so I can pull in JSON content and put it in the right place. If the right place exists, I'll just update the content. If it doesn't exist, I'll create it.)