Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript load src javascript file Reply To: load src javascript file

#185849
jamygolden
Member

I’m not really sure I understand you, but your example function wouldn’t work as you are settings counts=2 within your if statement which will always be true.

 jQuery(function($) {
    var counts = 1;

    $(document).click(function() {
        counts++;

        if (counts === 3) {
           var scriptEl = document.createElement('script');
           scriptEl.src = 'http://example/address-here.js';
           document.body.appendChild(scriptEl);
      }
  });
})

That will add a script file to the page if a user clicks on the document twice.