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

New To Dom Scripting, having some issues

gregerly
192 Expert 100+
The script I'm trying to write has no real world use, I'm just practicing on working with nodes etc.... The html markup is simple, just a div and a button, when you click the button, a text node is appended to the div, and the button is removed, a new button is added. the new button has setAttribute("onclick","remove()") which removes the text node written to the screen with the previous button click. This works as expected in Firefox, while IE will add the new text node, create the new button, but the remove() function is not run when the button is clicked. Viewing the current DOM does show the onclick=remover() however. The main html markup and javascipt is below:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" language="javascript">
  2. function main(){
  3. var main      = document.getElementById("main");
  4. var bld        = document.createElement("h1");
  5. bld.setAttribute("id","bigText");
  6.  
  7. bld.appendChild(document.createTextNode("Greg is Great"));
  8. main.appendChild(bld);
  9.  
  10. var input    = document.getElementById("mybutton");
  11. input.parentNode.removeChild(input);
  12.  
  13. var newbutton= document.createElement("input");
  14. newbutton.setAttribute("type","button");
  15. newbutton.setAttribute("value","Remove Text");
  16. newbutton.setAttribute("onclick","remove()");
  17. newbutton.setAttribute("id","mybutton");
  18.  
  19. main.appendChild(newbutton);
  20. }
  21.  
  22. function remove(){
  23. var bigText = document.getElementById("bigText");
  24. bigText.parentNode.removeChild(bigText);
  25.  
  26. var input    = document.getElementById("mybutton");
  27. input.parentNode.removeChild(input);
  28.  
  29. var newbutton2= document.createElement("input");
  30. newbutton2.setAttribute("type","button");
  31. newbutton2.setAttribute("value","Click Me");
  32. newbutton2.setAttribute("onclick","main()");
  33. newbutton2.setAttribute("id","mybutton");
  34.  
  35. var main = document.getElementById("main");
  36. main.appendChild(newbutton2);
  37.  
  38. }
  39. </script>
  40. <title></title>
  41. </head>
  42. <body>
  43.      <div id='main'></div>
  44. <input id='mybutton' type='button' onClick='main()' value="Click Me"/>
  45. <a onClick="javascript:objWin=window.open('','objWin','width=600,height=450,scrollbars=yes,resizable=yes');objDoc=objWin.document;objDoc.open('text/plain');objDoc.write(document.documentElement.outerHTML);objDoc.close();">View current DOM</a>
  46. </body>
  47. </html>
The HREF in the html above is just used to view the current state of the dom. It helps a newbie like me. After reading a bit on this board I've realized that there are probably easier ways of doing things, but Im just trying to get my head around "Traversing the DOM". Thanks for any help anyone can give me.

Greg
Sep 2 '06 #1
1 2003
acoder
16,027 Expert Mod 8TB
You can't use setAttribute to set onclick in IE. Try this instead:
Expand|Select|Wrap|Line Numbers
  1. newbutton.onclick=remove;
Nov 5 '07 #2

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

Similar topics

50
by: Edward K. Ream | last post by:
I would like to say a few (actually more than a few) words here about some recent discoveries I have made concerning the interaction of Leo and Python. If you don't want to hear an inventor enthuse...
22
by: Ajay | last post by:
hi! is there an authoritative source on the performance of scripting languages such as python vs. something like java, c, c++. its for a report, so it would be awesome if i could quote some...
33
by: Quest Master | last post by:
I am interested in developing an application where the user has an ample amount of power to customize the application to their needs, and I feel this would best be accomplished if a scripting...
8
by: Rodd Snook | last post by:
I have an application which makes extensive use of the Scripting.Dictionary object. I'm not doing anything silly like putting them outside the page scope -- just creating quite a few of them and...
9
by: Vijai Kalyan | last post by:
Hello All, I have a few questions which you might seem irrelavant and/or foolish. I am asking anyway so I can find out. 1. Is XSL as powerful as a programming language such as Java in its...
15
by: Birahim FALL | last post by:
Hi, I'm very fresh to PostgreSQL, coming from Oracle. I want to developp web applications based on apache and postgresql. Is there an equivalent of OWA server (Oracle Web Application server) for...
17
by: Karl Irvin | last post by:
To use the Textstream object, I had to set a Reference to the Microsoft Scripting Runtime. This works good with A2000 Is the Scripting Runtime included with A2002 and A2003 so the Reference...
7
by: Scott M. | last post by:
How can I disable the cross-site scripting check for one particular page of a site?
1
by: torsten.reiners | last post by:
Hi, We try to implement a "web-application" where we have to access a general web-site -- loaded into a frame -- from another frame using JavaScript. We know that there are security issues...
2
by: Michael Kintner | last post by:
Strange thing happening with Windows 2000 to Windows 2003 R2 This ASP script below is sitting on a Windows 2000 IIS Server Box and the fldr was pointing to \\Bradford2\temp which was a Windows...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.