Exception thrown in event listener: "Error: Syntax error, unrecognized expression: #articleboard/board1" Google dfp

While I was working on Google's DoubleClick for Publishers ads the console was showing the following errors:

"Error: Syntax error, unrecognized expression: #articleboard/board1"

Pattern of the error

I had quite a lot of ads on my website and the adunit IDs are topbanner, netbanner, articleboard etc. I also had some ads those IDs are articleboard/board1, articleboard/board2, articleboard/board3. The error was only happening for articleboard/board1 types of ads. 

Reason of the error

I was using a jQuery plugin to load the ads on my website. This plugin was not able to read the adunit element from the DOM if the DOM element has the ID with a forward slash (/). For example: 

<div class="adunit-lazy" id="netbanner/banner1" 
data-name="netbanner/banner1" data-size-mapping="netmapping">
</div>

Solution of the error

To solve the above issue we need to escape the forward slash of the adunit ID. In  JavaScript the following will solve this error: 

 adunitId.replace('/', '\\/');

Comments