473,750 Members | 2,458 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reference Gets Lost After Repainting the HTML Object

Please, explain an interesting phenomenon, if you can. I have an array
of references to an HTML element:

<div id='container'>
<div id='someId1'></div>
<div id='someId2'></div>
</div>
.....
myArray["someId1"] = document.getEle mentById("someI d1");
myArray["someId2"] = document.getEle mentById("someI d2");

If I repaint these HTML elements like this:
document.getEle mentById("").in nerHTML="<div id='someId1'><d iv
id='someId2'></div>"
with the same IDs, the reference to my objects in myArray is lost but
the element seems to exist, not on the webpage, though.

Do I need to build a new reference array when repainting the HTML
elements?
Where are the old elements which seem to still exist?
(myArray["someId2"]=="[object]")

May 2 '07 #1
2 2135
vu******@gmail. com wrote:
Please, explain an interesting phenomenon, if you can. I have an array
of references to an HTML element:

<div id='container'>
<div id='someId1'></div>
<div id='someId2'></div>
</div>
....
myArray["someId1"] = document.getEle mentById("someI d1");
myArray["someId2"] = document.getEle mentById("someI d2");

If I repaint these HTML elements like this:
document.getEle mentById("").in nerHTML="<div id='someId1'><d iv
id='someId2'></div>"
What is the empty string parameter to getElementById( ) supposed to do?
with the same IDs, the reference to my objects in myArray is lost but
the element seems to exist, not on the webpage, though.
Where did you get the term 'repaint' from? You aren't repainting those div
elements, you are replacing them with completely different div elements.
The array will still reference the original elements, but they are no
longer on the page.
Do I need to build a new reference array when repainting the HTML
elements?
Yes, or better yet use DOM methods to manipulate the existing elements
instead of replacing them. For example, you could empty the existing div
elements like this:

function emptyNode(node) {
while (node.firstChil d) {
node.removeChil d(node.firstChi ld);
}
}
emptyNode(myArr ay["someId1"]);
emptyNode(myArr ay["someId2"]);
Where are the old elements which seem to still exist?
(myArray["someId2"]=="[object]")
The old elements will exist as long as you still reference them but are no
longer used in the displayed page. You could put them back into the DOM if
you wanted.
May 2 '07 #2
If I repaint these HTML elements like this:
document.getEle mentById("").in nerHTML="<div id='someId1'><d iv
id='someId2'></div>"
What is the empty string parameter to getElementById( ) supposed to
do?

Thank you. I thought this to be that way. Correction:

document.getEle mentById("conta iner").innerHTM L="<div id='someId1'><d iv
id='someId2'></div>"
May 2 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1301
by: Mike Richardson | last post by:
Hello, I am using VB.net. Is there a way to stop the screen from repainting. I would perfer to stop screen repainting for the entire application. Example when a form is loading. Stop repainting. Execute code. restore repainting. In VB 6 I called
13
17929
by: Abe Frohnman | last post by:
Hello all, I'm passing a reference to a class into the constructor of a form, like so: public MyForm(int count, ref Area myArea) {...} How can I use myArea outside the constructor? Should I create another Area and assign myArea to it (ie: Area foo = myArea;) or is there a better way? ~AF
5
1553
by: Javier Campos | last post by:
WARNING: This is an HTML post, for the sake of readability, if your client can see HTML posts, do it, it doesn't contain any script or virus :-) I can reformat a non-HTML post if you want me to (and if this doesn't see correctly with non-HTML viewers) Ok, I'm fed up with this so I'll explain the situation here and my approach (which sucks), and see if anyone can give a better solution to this. I'm making a way to have several parameters...
3
3848
by: Tom | last post by:
I have a VB .NET application that has a text box with the following code to handle the leave event. Private Sub txtIDiscountRate_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtIDiscountRate.Leave If txtIDiscountRate.Text.Trim <> "" AndAlso _ MsgBox("Are you sure you want to use a non- default discount rate?", MsgBoxStyle.OKCancel) _ = MsgBoxResult.Cancel Then
18
3533
by: man | last post by:
can any one please tell me what is the diff between pointer and reference.....and which one is better to use ....and why???????
2
4292
by: David W. Fenton | last post by:
I think at various times we've all encountered this problem: A subform is on a main form. From the code of the main form we refer to some property of/control on the child form thus: Me!subForm.Form!txtTextBox and for some reason, in certain contexts, we get the error: Error 2455: You entered an expression that has an invalid reference
8
2402
by: toton | last post by:
HI, One more small doubt from today's mail. I have certain function which returns a pointer (sometimes a const pointer from a const member function). And certain member function needs reference (or better a const reference). for eg, const PointRange* points = cc.points(ptAligned);
15
2678
by: arnuld | last post by:
-------- PROGRAMME ----------- /* Stroustrup, 5.6 Structures STATEMENT: this programmes *tries* to do do this in 3 parts: 1.) it creates a "struct", named "jd", of type "address". 2. it then adds values to "jd" 3.) in the end it prints values of "jd".
275
12349
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
8840
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9584
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9399
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9259
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8266
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6083
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4895
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3328
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2811
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.