javascript question, DOM api
ok here's the deal. lets say i have two div tags and i want to swap the content of these two divs with javascript. it's not too hard to do using innerHTML to get/set the content of those divs, but i'm running into cross-browser compatibility issues by using innerHTML. namely, newer than 1.3 safari on mac. i have to deal with this, because about 25% of my audience with this will be on exactly that browser. i'm at my wits end here, stuff that *should* work just doesnt.
[HTML]
<div id="divOne">
<p> Some content here...</p>
</div>
<div id="divTwo">
<p> Another bit of content here</p>
</div>
[/HTML]
what i want is to click a button and put divOne's content into divTwo and vice versa, all in one step, without setting content using innerHTML.
any ideas?
[HTML]
<div id="divOne">
<p> Some content here...</p>
</div>
<div id="divTwo">
<p> Another bit of content here</p>
</div>
[/HTML]
what i want is to click a button and put divOne's content into divTwo and vice versa, all in one step, without setting content using innerHTML.
any ideas?
0
Comments
[PHP]
function moveUp(userId, moduleId, modDiv) {
var elem = document.getElementById(modDiv);
var elemParent = elem.parentNode;
var parentDiv = elemParent.parentNode;
var modulePosition = parseInt(elemParent.id.substring('string'.length));
alert(modulePosition + '\n' + parentDiv.id);
if (modulePosition > 1) {
var fromDivOne = document.createDocumentFragment(elem.innerHTML);
var elemTwo = parentDiv.childNodes[modulePosition - 1];
alert(elemTwo.innerHTML);
var fromDivTwo = document.createDocumentFragment(elemTwo.innerHTML);
parentDiv.replaceChild(fromDivTwo, parentDiv.childNodes[modulePosition]);
//alert(fromDivOne + '\n' + parentTwo.childNodes[modulePosition].id);
//parentTwo.replaceChild(fromDivOne, parentTwo.childNodes[1]);
}
}
funtion moveDown(userId, moduleId, modDiv){
//to be written
}
[/PHP]
[HTML]
<div id="boxOne">
<div id="swappableOne">
<div id="buttons">
<img alt="Up" src="buttonSrc" onclick="moveUp('userId', '1', 'swappableOne')" border="0">
<img alt="Down" src="buttonSrc" onclick="moveDown('userId', '1', 'swappableOne')" border="0">
</div>
<div id="divBody">
stuff....
</div>
</div>
<div id="boxTwo">
<div id="swappableTwo">
<div id="buttons">
<img alt="Up" src="buttonSrc" onclick="moveUp('userId', '2', 'swappableTwo')" border="0">
<img alt="Down" src="buttonSrc" onclick="moveDown('userId', '2', 'swappableTwo')" border="0">
</div>
<div id="divBody">
other stuff....
</div>
</div>
</div>
[/HTML]
still glitchy but gettin closer. i'm definitely learning more about javascript. i dont like it lol
basically: