Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+10 votes
in Q2A Core by
edited by

I have created this code to insert adsense ads between questions loop, this code is working fine for me, Is there anyone know any other methods? to insert ads between loops, if know please let me know.


window.addEventListener('DOMContentLoaded', function() {

    const posts = document.querySelectorAll('.qa-q-list-item');

    const adCode = '<div class="ad-container">ad code goes here</div>';

    let count = 0;

    for (let i = 0; i < posts.length; i++) {


        if (count === 2) {

            const adContainer = document.createElement('div');

            adContainer.innerHTML = adCode;

            posts[i].parentNode.insertBefore(adContainer, posts[i].nextSibling);

            count = 0;




Q2A version: Version 1.8.6
use q2a simple ads plugin

Please log in or register to answer this question.