I have code that moves around divs. It's supposed to happen out of the user's view. But whenever I clear my cache and refresh the page to test it, I see these divs moving around every time! It's super annoying visually...
I have 2 ways of doing it, and both I can see visually occur.
1st way:
//START MOVE
[...document.querySelectorAll('#primary')].forEach(x => {
moveElement(
x.querySelector('.snax-voting-container-body'),
x.querySelector('.object1')
//x.querySelector('.snax-voting-container-body')
);
});
/**
* Moves an element by detaching it from its parent and appending it to
* a target.
* @param {HTMLElement|String} ref - Element to detach and move
* @param {HTMLElement|String} target - Element where ref will be appended
* @return Returns the element that was moved
*/
function moveElement(ref, target) {
if (typeof target === 'string') target = document.querySelector(target);
target.appendChild(detatchElement(ref));
return ref;
}
/**
* Detaches an element from its parent.
* @param {HTMLElement|String} ref - Element to detach from its parent
* @return Returns the detached element
*/
function detatchElement(ref) {
if (typeof ref === 'string') ref = document.querySelector(ref);
return ref.parentElement.removeChild(ref);
}//end of MOVE
Second way:
$('.object1').append( $('.snax-voting-container-body') );
Any ideas why this is happening-- why I can actually see this process despite having it in $(document).ready(function () {? Thanks.