Untitled
unknown
plain_text
a year ago
2.1 kB
14
Indexable
(function() {
// Function to wait for an element to appear before proceeding
function waitForElement(selector, trigger, delayInterval, delayTimeout) {
var interval = setInterval(function() {
if (document && document.querySelector(selector)) {
clearInterval(interval);
trigger();
}
}, delayInterval);
setTimeout(function() {
clearInterval(interval);
}, delayTimeout);
}
let eg_string=`
<div class="eg_text_section">
<h1>hellow</h1></div>
`
//function to add new setion
function init() {
/* Find the target element */
let selector = document.querySelector('.d-block.d-md-flex');
/* Ensure the element exists before inserting */
if (selector) {
selector.insertAdjacentHTML('afterbegin', eg_string);
}
}
// Function to swap the sections
function swapSections() {
// Get the two sections
const topSection = document.querySelector('.s-logos'); // Top section
const bottomSection = document.querySelector('.s-logo-slider'); // Bottom section
// Ensure both elements exist and have the same parent
if (topSection && bottomSection) {
const parentTopSection = topSection.parentNode;
const parentBottomSection = bottomSection.parentNode;
console.log("Parent of Top Section:", parentTopSection);
console.log("Parent of Bottom Section:", parentBottomSection);
// Check if they share the same parent
if (parentTopSection === parentBottomSection) {
// Swap the sections by moving the top section after the bottom section
parentTopSection.insertBefore(bottomSection, topSection); // Moves bottom section before the top section
} else {
console.error("Sections do not share the same parent. Swapping cannot be performed.");
}
} else {
console.error("One or both sections not found in the DOM.");
}
}
// Wait for both sections to be available in the DOM, then trigger the swap
waitForElement('.s-logos', swapSections, 50, 15000);
})();
Editor is loading...
Leave a Comment