Former Member
inherit
guest@proboards.com
155913
0
Nov 29, 2024 3:43:29 GMT -8
Former Member
0
January 1970
Former Member
|
Post by Former Member on Aug 17, 2011 22:13:23 GMT -8
Why wont this work as a function?
<script type ="text/javascript"> function move() { document.write("<div id='welcometable'></div>") var wTable = document.getElementsByTagName("TABLE")[0] wTable.parentNode.removeChild(wTable) wTable.style.marginTop="25px" document.body.replaceChild(wTable,document.getElementById('welcometable')) } </script>
<input type= "button" value= "moveWT" onclick= "move()">
As we all know, the script works outside of the functon, but why wont it work inside of the function? Just curious for a little project I'm working on.
|
|
inherit
134992
0
May 26, 2012 2:38:57 GMT -8
SubDevo
Creator of LSD...
3,861
December 2008
subdevo
|
Post by SubDevo on Aug 17, 2011 23:01:57 GMT -8
You can't to a document.write after the page has loaded. Using your example, if you move the div above the script as regular html and remove the doc write line, then it should work.
<div id='welcometable'></div>
<script type ="text/javascript"> function move() { var wTable = document.getElementsByTagName("TABLE")[0] wTable.parentNode.removeChild(wTable) wTable.style.marginTop="25px" document.body.replaceChild(wTable,document.getElementById('welcometable')) } </script>
<input type= "button" value= "moveWT" onclick= "move()">
FYI... If the forum is using a banner under ads code with a border around forum or side tables, the welcome table will no longer be the first table in the DOM. So document.getElementsByTagName("TABLE")[0] will not grab the correct table. I know you are probably using this example for testing, but I thought I should mention it.
|
|
Former Member
inherit
guest@proboards.com
155913
0
Nov 29, 2024 3:43:29 GMT -8
Former Member
0
January 1970
Former Member
|
Post by Former Member on Aug 18, 2011 0:02:19 GMT -8
Ok, that works. Everything makes sense now. Thanks Sub.
BTW, I didn't think about the fact that you mentioned with the welcome table. Though it is true, fortunately I don't believe it is going to effect what I am doing. Thanks again
|
|