Load reCAPTCHA dynamically : <p>There are several ways to load reCAPTCHA using javascript such as below:</p>

<pre><code>&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;Loading captcha with JavaScript&lt;/title&gt;
&lt;script src="https://code.jquery.com/jquery-1.12.0.min.js"&gt;&lt;/script&gt;
    &lt;script type='text/javascript'&gt;
    var captchaContainer = null;
    var loadCaptcha = function() {
      captchaContainer = grecaptcha.render('captcha_container', {
        'sitekey' : 'Your sitekey',
        'callback' : function(response) {
          console.log(response);
        }
      });
    };
    &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div id="captcha_container"&gt;&lt;/div&gt;
      &lt;input type="button" id="MYBTN" value="MYBTN"&gt;
      &lt;script src="https://www.google.com/recaptcha/api.js?onload=loadCaptcha&amp;render=explicit" async defer&gt;&lt;/script&gt;
  &lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>This code load captcha on pageload. I want load reCAPTCHA just when clicked on "MYBTN". So the code changes into:</p>

<pre><code>&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;Loading captcha with JavaScript&lt;/title&gt;
&lt;script src="https://code.jquery.com/jquery-1.12.0.min.js"&gt;&lt;/script&gt;
    &lt;script type='text/javascript'&gt;
$('#MYBTN').on('click',function(){
    var captchaContainer = null;
    var loadCaptcha = function() {
      captchaContainer = grecaptcha.render('captcha_container', {
        'sitekey' : 'Your sitekey',
        'callback' : function(response) {
          console.log(response);
        }
      });
    };
 });
    &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div id="captcha_container"&gt;&lt;/div&gt;
      &lt;input type="button" id="MYBTN" value="MYBTN"&gt;
      &lt;script src="https://www.google.com/recaptcha/api.js?onload=loadCaptcha&amp;render=explicit" async defer&gt;&lt;/script&gt;
  &lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>But this code didn't work when I click on "MYBTN" and reCAPTCHA not load.
Help me plz. Thanks.</p>
