johnnyb
09-21-2006, 09:40 PM
Hi,
I'm writing a script where the user clicks a button and a function is called that clones the last child of the node right before the button. Here's the function, (it's a bit funky for debugging):
function anothervideo()
{
var marker = document.getElementById("addmore");
var prev=marker.previousSibling;
var preprev = prev.previousSibling;
var parent=marker.parentNode;
var newvid = prev.cloneNode(true);
alert(prev.tagName);
//parent.insertBefore(newvid, marker);
}
And here's the HTML around the button:
</div>
</fieldset>
</li>
</ol>
<input type="button" value="Add Another Video" onclick="anothervideo();" id="addmore"/>
This is only the excerpt leading up to the button. The rest of my XHTML is correct and valid - I checked.
So, as it stands now when the button is clicked it should alert 'OL' but instead it alerts 'undefined'. When I alert(typof prev) it says it's an object.
If I alert preprev.tagName, (the sibling before the one before the button), it echos 'OL'! It seems that Firefox thinks there is an extra element in between the <ol> and the <input type="button">.
It works as expected in IE6 but I need it to run cross-browser.
Has anyone else experienced this and does anyone know how to fix it?
John
Resolved: There was a line break before the button that FF was treating as a text node.
I'm writing a script where the user clicks a button and a function is called that clones the last child of the node right before the button. Here's the function, (it's a bit funky for debugging):
function anothervideo()
{
var marker = document.getElementById("addmore");
var prev=marker.previousSibling;
var preprev = prev.previousSibling;
var parent=marker.parentNode;
var newvid = prev.cloneNode(true);
alert(prev.tagName);
//parent.insertBefore(newvid, marker);
}
And here's the HTML around the button:
</div>
</fieldset>
</li>
</ol>
<input type="button" value="Add Another Video" onclick="anothervideo();" id="addmore"/>
This is only the excerpt leading up to the button. The rest of my XHTML is correct and valid - I checked.
So, as it stands now when the button is clicked it should alert 'OL' but instead it alerts 'undefined'. When I alert(typof prev) it says it's an object.
If I alert preprev.tagName, (the sibling before the one before the button), it echos 'OL'! It seems that Firefox thinks there is an extra element in between the <ol> and the <input type="button">.
It works as expected in IE6 but I need it to run cross-browser.
Has anyone else experienced this and does anyone know how to fix it?
John
Resolved: There was a line break before the button that FF was treating as a text node.