Home › Forums › JavaScript › load src javascript file › Reply To: load src javascript file
October 9, 2014 at 3:03 am
#185849
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.