Removing document.createElement element

I’ve written the following small feature test.

var _delete = (function(el, prop){
  try {
    var div = document.createElement('div'); div._xyz = 1;	
    delete(div._xyz);
    return function(el, prop){ delete el[prop] };
  } catch(e){
    return function(el,prop){ el.removeAttribute(prop) };
  }
}());

I want to remove ‘div’ before returning the function. Testing in IE something like div.parentNode.removeChild(div); will fail. If I look in the dom 'div’s parentNode is null, so that explains that. It needs to be appended to something first I guess.

What’s the best way of going about this?

I guess I could append a unique Id to the body, but I’m trying to avoid that.

How about simply delete div; ?

Thanks

RLM

If I temporarily use the body this seems to work okay. Would like to know how to go down the document.createElement route.

var _delete = (function(el, prop){
  try {
	var body = document.body, tmpId = '_tmpId:' + new Date();	
	body[tmpId] = 1;
	delete body[tmpId]; // try this
	return function(el, prop){ delete el[prop] };
  } catch(e){
	body.removeAttribute(tmpId);
    return function(el,prop){ el.removeAttribute(prop) };
  }
}());

alert(_delete.toString());

RLM