Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delete object from browser

Status
Not open for further replies.

cleary1981

Programmer
Jun 10, 2008
4
GB
Can anyone help me I need to be able to delete a specified object. Heres the function I used to create the object.

Code:
function showObject (){
	if (request.readyState == 4) {
	var returned = request.responseText;
	var splitResult = returned.split(" ");
	var h = splitResult[0];
	var w = splitResult[1];	// the dimensions must be set to a scale as they are to big for the screen. 25px represents 100mm
	h = h/5;
	w = w/5;
		
	cv = document.getElementById("canvas");
	newObject = document.createElement('div');
	newObject.Class = g_objName;
	newObject.id = "newObject";
	newObject.innerHTML = g_objName;
	newObject.alt = g_objName;
	newObject.style.height = h;
	newObject.style.width = w;
	newObject.onmousedown=function(){grab(this);}	
	cv.appendChild(newObject);
}
}
 
[tt]var obj=document.getElementById("newObject");
obj.parentNode.removeChild(obj);[/tt]
 
yeah but what I don't understand is that I have more than one object with an ID=newObject I need to be able to remove them by the value of the innerHTML
 
>I have more than one object with an ID=newObject
Don't do that, in particular when the script is under your control.
[tt]
var s=document.getElementById("canvas").innerHTML;
s=s.replace(/<div\s[^>]*?id=("|')newObject\1\s[^>]*?>[\s\S]*?<\/div>/gi,"");
document.getElementById("canvas").innerHTML=s;[/tt]
 
Amendment
A minimal improvement.
[tt]var s=document.getElementById("canvas").innerHTML;
s=s.replace(/<div\s[^>]*?id=("|')newObject\1[^>]*?>[\s\S]*?<\/div>/gi,"");
document.getElementById("canvas").innerHTML=s; [/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top