Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+10 votes
267 views
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.

<script>

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++) {

        count++;

        if (count === 2) {

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

            adContainer.innerHTML = adCode;

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

            count = 0;

        }

    }

});



</script>
Q2A version: Version 1.8.6
by
use q2a simple ads plugin

Please log in or register to answer this question.

...