Removing injected Javascript ads from a list item
<p>I have written some Javascript to inject ads into an article. The ads are injected into a certain point in the article based on how many characters or paragraphs are displayed.</p>
<p>The issue I have is that when there is an unordered list on the page, the jaavscript ads will inject themselves into a list item. This then throws off the formatting slightly as they are indented along with the rest of the list items.</p>
<p>Is there a Javascript way to make sure these ads do not get injected into a list and only stick to being injected in paragraph tags?</p>
<p>An example of the code is below. The below sets up the vtext ads:</p>
<pre><code>setupVText() {
    const longArticle = this.articleLength &gt; shortestArticle;
    const noVideos = !this.elements.videos.length;
    const noAdInitiated = !this.vTextHasInit;

    // only init if article is long enough and
    // the article does not have any videos
    // the v text add has not already been initiated
    if ( longArticle &amp;&amp; noVideos &amp;&amp; noAdInitiated ) {
        this.vTextOptions = {
            title: 'ADVERTISEMENT',
            vptags: this.setTags(),
            vpcategory: this.setCategory(),
            divid: 'vtext-container',
            identifier: 'uk-dev',
            injectAfter: this.injectAfterParagraph(this.paragraphLengths)
        };

        window.addEventListener('resize', event =&gt; {
            // debounce resize event
            if (typeof this.resizeTimeout !== 'undefined') clearTimeout(this.resizeTimeout);
            this.resizeTimeout = setTimeout(this.resize.bind(this), 300);
        });

        this.vTextHasInit = true;
        this.injectContainer();
        this.setContainerDimensions();
        this.serveAd();
    }
}
</code></pre>
<p>and the below code here injects it into the page depending on character count or paragraph length:</p>
<pre><code>injectAfterParagraph(paragraphLengths) {
    let characterCount = 0;

    for (const paragraph in paragraphLengths) {
        // loop through paragraphs and add length to characterCount
        characterCount += paragraphLengths[paragraph];

        // if count goes above character limit return paragraph number
        if (characterCount &gt;= injectAfterChar) {
            // return paragraph or 1 if paragraph is 0
            window.paragraph = paragraph;
            return parseInt(paragraph) || 1;
        }
    }
}
</code></pre>