...

View Full Version : Javascript appendchild executing twice Javascript appendchild executing twice



learner guy
01-24-2012, 03:14 PM
function displayResult()
{
var damn = document.getElementById("textyar").value;
document.getElementById("oneforty").innerHTML = damn;
var newDIV = document.createElement('div');
newDIV.className = "tweets";
var newspan =document.createElement('span');
newspan.className = "imagespanleft";
var img = document.createElement("IMG");
img.className="image";
img.src = "tweets/me.jpg";
newDIV.innerHTML = document.getElementById('textyar').value;
document.getElementById('leftmaindiv').appendChild(newDIV).appendChild(newspan).appendChild(img);
}


this is the code , i m trying to create an interface like twitter where u put in text box and tweet appears below in
problem is it is creating two divs instead of one , i tried insertbefore() as well but same behaviour
plz ask any questions if u r still not clear

felgall
01-24-2012, 08:41 PM
Does it happen in all browsers or just in some?

innerHTML doesn't always update the DOM properly when you use it and so trying to apply DOM methods to code where some of it has been updated that way doesn't always work. You might need to replace the second last line with creating a textNode to contain the value and appendChild that to the div instead of using innerHTML.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum