function rearrange(x, y) {
x.parentNode.replaceChild(x, y);
x.parentNode.insertBefore(y,x);
}
If I do
var a = document.getElementsByClassName('btn-button-google')[0];
var b = document.getElementsByClassName('btn-button-doodle')[0];
rearrange(b,a);
I get the following error
NotFoundError: Failed to execute 'replaceChild' on 'Node': The node to be replaced is not a child of this node.
Which I understand since a is in one html div and b is in another div, but I'm curious as how to fix this from happening. this works
rearrange(b.parentNode,a.parentNode);
Since they are in the same node.
Example HTML
<div class="container">
<div class="group">
<a href="" class="btn-button-bold"><a>
<a href="" class="btn-button-italic"><a>
<a href="" class="btn-button-strike"><a>
</div>
<div class="group">
<a href="" class="btn-button-font"><a>
<a href="" class="btn-button-ffamily"><a>
<a href="" class="btn-button-google"><a>
</div>
<div class="group">
<a href="" class="btn-button-smilies"><a>
<a href="" class="btn-button-doodle"><a>
<a href="" class="btn-button-source"><a>
</div>
</div>