473,396 Members | 1,689 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,396 software developers and data experts.

insert element in DOM

I'm trying out a script called mktree.js
< http://www.mattkruse.com/javascript/mktree/ >
I want to add an expand all button to the script, using the DOM
insertBefore method. I added a function to the mktree.js script, but
it failed to insert the button I created. However, Firefox's javscript
console did not report an error. AFAICS, it didn't find the element
with id="root".

I made a second page, this time putting the script to insert the
button inside the page itself, and it worked. I'm confused why the
funtion fails in the external js file, not inside the html document.

The test cases can be found here:

< http://www.tsmchughs.com/test/insert/ >

--
Brian (remove ".invalid" to email me)
http://www.tsmchughs.com/
Jul 23 '05 #1
2 2289
Ivo
"Brian" wrote
insertBefore method. I added a function to the mktree.js script, but
it failed to insert the button I created. However, Firefox's javscript
console did not report an error. AFAICS, it didn't find the element
with id="root".

I made a second page, this time putting the script to insert the
button inside the page itself, and it worked. I'm confused why the
funtion fails in the external js file, not inside the html document.

The test cases can be found here:

< http://www.tsmchughs.com/test/insert/ >


Simple. In your external file the code responsible for adding the button is
called before the page renders, before there is an element with id=root. Run
it onload and you should be fine. In the internal version, the button code
is placed at the end, when the element is there already.
Also,
newButton = document.createElement("BUTTON");
newButton.setAttribute("type", "button");
seems odd. What other type can a button be?
HTH
Ivo
Jul 23 '05 #2
Ivo wrote:
"Brian" wrote
insertBefore method. I added a function to the mktree.js script,
but it failed to insert the button I created.

The test cases can be found here:

< http://www.tsmchughs.com/test/insert/ >
Simple. In your external file the code responsible for adding the
button is called before the page renders, before there is an
element with id=root. Run it onload and you should be fine.


Gawd I can be such a dolt sometimes. The script adds the main function
to window.onload, but the mkButtons script was run as is. I added it
to onload, and works fine now. If you knew how long I tore my hair
out over this. :-/
newButton = document.createElement("BUTTON");
newButton.setAttribute("type", "button"); seems odd. What other type can a button be?


submit (the default) and reset

http://www.w3.org/TR/html4/interact/...ml#edef-BUTTON

--
Brian (remove ".invalid" to email me)
http://www.tsmchughs.com/
Jul 23 '05 #3

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

Similar topics

15
by: Jack | last post by:
I have a text file of data in a file (add2db.txt) where the entries are already entered on separate lines in the following form: INSERT INTO `reviews` VALUES("", "Tony's", "Lunch", "Great...
4
by: mike | last post by:
Hello. Let's say I have the following XML document: <ROOT><Element1>Some Text</Element1></ROOT> I want to add a new element after Element1. I tried the following but, naturally, it doesn't...
5
by: Andrew | last post by:
Hi, friends, In ASP, we use obj = CreateObject("com.dll") obj.GetHTMLText(inVal, outHTMLTxt1, outHTMLTxt2) to get different HTML strings based on input values. Then, we insert them into...
28
by: Giggle Girl | last post by:
Can someone show me how to insert a row at any given row index of an already created table? It only has to work in IE6 (used on intranet at work). Specifically, if a table is 20 rows in total...
2
by: mirandacascade | last post by:
O/S: Win2K Vsn of Python: 2.4 Example: <a> <b createAnotherWhenCondition="x"> <c>text for c</c> <d>text for d</d> </b>
6
by: flash | last post by:
write a program that manipulates arrays of integers. The main program should call three functions: Insert, Delete, and Search. The Insert function should call a function Sort that sorts the array. ...
4
by: Tim Slattery | last post by:
It would be convenient for my app to store the stuff I'm generating in a std::list. I'd like to remember the location of a particular place in the list - sort of like sticking my finger into it -...
7
by: Jim Langston | last post by:
I'm working on a program, and at one time I find it necessary to load classes into a map. Now, these classes don't have default constructors, so I can't retrieve them using MyMap. So I wound...
1
by: subramanian100in | last post by:
Suppose I have vector<intvi; deque<intdi; list<intli; Suppose all of these containers have some elements. Suppose 'v_iter' is an iterator pointing to some element in 'vi'. Suppose 'v_beg'...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...

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.