473,405 Members | 2,167 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

delete an object

178 100+
Can anyone help me. I need a function to delete an object. Here is the function I use to create objects.

Expand|Select|Wrap|Line Numbers
  1. function showObject (){
  2.     if (request.readyState == 4) {
  3.     var returned = request.responseText;
  4.     var splitResult = returned.split(" ");
  5.     var h = splitResult[0];
  6.     var w = splitResult[1];    // the dimensions must be set to a scale as they are to big for the screen. 25px represents 100mm
  7.     h = h/5;
  8.     w = w/5;
  9.  
  10.     cv = document.getElementById("canvas");
  11.     newObject = document.createElement('div');
  12.     newObject.Class = g_objName;
  13.     newObject.id = "newObject";
  14.     newObject.innerHTML = g_objName;
  15.     newObject.alt = g_objName;
  16.     newObject.style.height = h;
  17.     newObject.style.width = w;
  18.     newObject.onmousedown=function(){grab(this);}    
  19.     cv.appendChild(newObject);
  20. }
  21. }
  22.  
Jul 30 '08 #1
7 1485
acoder
16,027 Expert Mod 8TB
Use removeChild().
Jul 30 '08 #2
cleary1981
178 100+
Yeah but how do I removeChild where newObject.innerHTML is a specified value?
Jul 30 '08 #3
acoder
16,027 Expert Mod 8TB
If you have a number of divs, use getElementsByTagName("div") on the canvas and check the contents of each one.
Jul 30 '08 #4
cleary1981
178 100+
I can get the elements by tagname but I cant get at the one I want. Can anyone advise? Heres what ive been trying

Expand|Select|Wrap|Line Numbers
  1. var arr = new Array(); arr = document.getElementsByTagName("div");  //make array of all divs with id = newObject
  2.     // alert("Total Number of HTML Elements Found: " + document.documentElement.getElementsByTagName("div").length); 
  3.     for(var i=0; i < arr.length; i++) 
  4.         {
  5.             //check innerHTML against obj_name
  6.             alert("innerHTML" + document.documentElement.getElementsByTagName("*").item(i).nodeName);
  7.         }
Jul 31 '08 #5
acoder
16,027 Expert Mod 8TB
Use indexOf to find the specified string. You would against arr[i].innerHTML in the loop.

You can just get the div elements within the canvas element rather than the whole page if you use cv.getElementsByTagName("div") where cv is the canvas element.

Just a note that IDs should be unique. You can't have the same ID for more than one element in a page.
Jul 31 '08 #6
cleary1981
178 100+
changed the id and was able to do it quite simply. thanks
Jul 31 '08 #7
acoder
16,027 Expert Mod 8TB
Oh yes, of course, if you make each element unique, that pretty much solves your problem. Good to hear that it's sorted.
Jul 31 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

52
by: Newsnet Customer | last post by:
Hi, Statement 1: "A dynamically created local object will call it's destructor method when it goes out of scope when a procedure returms" Agree. Statement 2: "A dynamically created object...
1
by: Nimmi Srivastav | last post by:
There's a rather nondescript book called "Using Borland C++" by Lee and Mark Atkinson (Que Corporation) which presents an excellent discussion of overloaded new and delete operators. In fact there...
11
by: Jonan | last post by:
Hello, For several reasons I want to replace the built-in memory management with some custom built. The mem management itlsef is not subject to my question - it's ok to the point that I have...
1
by: Douglas Peterson | last post by:
class Allocator { public: virtual void * Alloc(size_t) = 0; virtual void * Free(void*) = 0; }; class Object { public:
11
by: Squid Seven | last post by:
I create a pointer to an item: CardSession *cardSession; Then, later, I use new to create an instance of the item and assign it to that pointer: cardSession = new CardSession(); In...
5
by: Jeff User | last post by:
Hello ..NET 1.1, VS 2003, C# & asp.net I have tried to follow msdn instructions and samples but I can not get an event to fire for this button on the datagrid. There has to be something obvious...
5
by: tom | last post by:
Hi, I'm overriding my operator new and operator delete for two classes, one inherited from the other, so I can use my own memory pool. A simplified version of what I have is below: class...
6
by: polocar | last post by:
Hi, I'm writing a program in Visual C# 2005 Professional Edition. This program connects to a SQL Server 2005 database called "Generations" (in which there is only one table, called...
9
by: Money | last post by:
If I allocate memory like this int *ptr = new int; Can I apply delete ptr; instead of delete ptr; since I am only allocating memory for 1 integer.
15
by: LuB | last post by:
I am constantly creating and destroying a singular object used within a class I wrote. To save a bit of time, I am considering using 'placement new'. I guess we could also debate this decision -...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.