Use onClick in chrome extension
<p>I have a chrome extension with <code>content_scripts</code>. When page loads i'm appending new element to <code>DOM</code> using jquery:</p>
<pre class="lang-js prettyprint-override"><code>urlTarget.parent().prepend(&quot;&lt;div class='scout status' onClick='test()' data-domain='&quot; + domainKey + &quot;'&gt;&lt;/div&gt;&quot;);
</code></pre>
<p>This works fine. I also defined a function inside my <code>inject.js</code> content script:</p>
<pre class="lang-js prettyprint-override"><code>function test() {
    alert(&quot;this is test&quot;);
    return false;
}
</code></pre>
<p>After clicking appended element i get following error:</p>
<p><code>Uncaught ReferenceError: test is not defined</code></p>
<p>I've been reading about security restrictions in chrome extension framework (see <a href="https://developer.chrome.com/extensions/contentSecurityPolicy#JSExecution" rel="nofollow noreferrer" title="docs">docs</a>), but i'm not sure if they are applied to content script also (documentation shows popup example), or am i am missing something else?</p>