YumJS insertBefore and insertAfter Documentation

insertBefore() and insertAfter()


insertBefore() and insertAfter() are Yum methods to insert elements at specific places the DOM.

In Yum you can do:


// Get first instances of these elements

const h2 = yum('h2').first;
const buttonNode = yum('.button').first;



// Yum insertBefore()

yum(h2).insertBefore('.button');// moves h2 to before first occurrence of .button 

//OR

yum(h2).insertBefore(buttonNode);// moves h2 to before buttonNode 



// Yum insertAfter()

yum(h2).insertAfter('.button');// moves h2 to after first occurrence of .button 


//OR

yum(h2).insertAfter(buttonNode);// moves h2 to after buttonNode 




//insert HTML after H2 (not recommended use _createNode)

yum('span inserted ').insertBefore(h2); // HTML span before h2 



Inserting HTML DOM strings before or after elements

(not recommended) use _createNode first then insert the result


// insertBefore using HTML strings

yum('<span>button inserted </span>').insertBefore(h2);


If you have any questions about Yum please contact me.