473,218 Members | 1,465 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,218 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 2286
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: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.