This page https://www.perlentaucher.de/static/yl-raw.html has a div at the beginning that I want to close.

If I run

parent.document.getElementById('div-gpt-ad-1407836088099-0').style.display='none'; 

in the console of Google Chrome, the div will close. However if I put this code inside of a google ad manager third party creative. I always get the error "Uncaught TypeError: Cannot read property 'style' of null"

Tag:google-ads-api, javascript

4 comments.

  1. Ahmed ElMetwally
    function addNewStyle(newStyle) { var styleElement = document.getElementById('styles_js'); if (!styleElement) { styleElement = document.createElement('style'); styleElement.type = 'text/css'; styleElement.id = 'styles_js'; document.getElementsByTagName('head')[0].appendChild(styleElement); } styleElement.appendChild(document.createTextNode(newStyle)); } addNewStyle('#div-gpt-ad-1407836088099-0 {display:none !important;}')

    before

    after

    1. error404

      Doesn't show any error in the console but not working yet :-( Thanks a lot

    2. error404

      it does work in the console, but not inside the line item creative :-/

  2. error404

    The problem was, that with each new ad unit's creative connected to that one was necessary to add parent. in the code. So at the end it looks like this:

    parent.parent.parent.parent.document.getElementById('div-gpt-ad-1407836088099-0').style.display='none';

Add a new comment.