setTimeout(function() {
var newElement = document.createElement('<a>New element</a>');
var X = document.getElementById('myDiv').appendChild(newElement);
var Y = document.getElementById('myDiv').childNodes.length;
}, 2000);
to create an element and add it to a div, but the newly instantiated element does not appear. var Y is increased every time I run the code, which in my mind means that an element is added, but does not appear. Any ideas???
I want to work with the DOM, adding and removing elements via Dynamic Scripts and this is very important. Thus far I can only append TextNodes!!!Cool?!
You posted nothing. Post your new code, after you have made the Fang's suggested changes, please. Better post a link to a test page, if any.
What I ment to say was that I tested in IE8 before posting in the first place, plus that had already tried Fangs suggestion.
Test page is not available I am working on my PC, experimenting with JavaScript, its not a project.
I think its has to to with the HTML structure of the document
I think its has to to with the HTML structure of the document
If you would like help, it would be advisable to post the updated code you are now using and the relevant HTML that pertains to that code. Otherwise, people are unlikely to waste their time trying to guess what you have and haven't done.
Great wit and madness are near allied, and fine a line their bounds divide.
Although the updated code is slightly modified there you go
Code:
setTimeout(function() {
var newElement = document.createElement('a');
var X = document.getElementById('myDiv').appendChild(newElement);
var Y = document.getElementById('myDiv').childNodes.length;
}, 2000);
the corresponding HTML is already posted on the top of the page, but there you go:
As suspected, you did not copy Fang's code correctly. You have been provided with the solution. Since you are so reticent and reluctant to provide information to those helping you in their free time, I won't "provide" you with the information again.
Last edited by Declan1991; 07-29-2010 at 12:56 PM.
Great wit and madness are near allied, and fine a line their bounds divide.
And Fang already told you that you have to modify that code. Which you didn't. So, how can you say that the Fang's advice doesn't work if you didn't apply it?
Bookmarks