Javascript not getting loaded

Viewed 36

I added a custom jquery function to my wordpress site. The code was to open a popup window on every alternative clicks. This doesn't work if I add to my wordpress theme header.php This is what I added <script src="/alternateclicks.js"></script> The js file was added to the wordpress root location public_html. I don't see any popup whatsoever.

jQuery(document).ready(function( $ ){
var canClick = 2;
$("body").click(function () {
    if (canClick%2==0) {
        window.open("https://example.com/").blur();
        window.focus();
        canClick = canClick+1;
    }
else {
canClick=canClick+1;}
});
});

The solutions I tried, I tried adding the code to footer.php. Didn't work. I added them using wp_enqueue. Didn't work.

UPDATE

In console am seeing that jquery is not defined. But I added the code only in footer.

1 Answers

Seems like, a Plugin interfered with my loading. The plugin disabled jquery. Found that the code worked in some pages and didn't work in some pages. Found out using the console. Then later when disabling the plugin perfmatters, jquery worked fine.

Related