I'm having a little problem with task for my new company. I need to write a script that basicly creates a html text and puts it on site using class selector (after a div to be sepcific). The problem is that we're using a custom CMS without any JS library so it has to be plain and the other obstacle I need to run only when element is loaded on page already (some kind of WaitForElement function is needed). JS noob here - can someone suggest a solution? Thank you in advance
I've tried a simple solution:
node = document.getElementsByClassName('class1 class2');
node.insertAdjacentHTML('afterend', '<p>text</p>');
And I've put something like this:
function waitForElement(elementId, callBack) { window.setTimeout(function() { var element = document.querySelectorAll(elementId); if (element.length) { callBack(elementId, element);} else { waitForElement(elementId, callBack); }}}
However I'm struggling to merge those two and running them on site.
text
');' However the problem is that I don't know how to make it run only after the element on page is loaded. – Qhr Aug 16 '22 at 06:38