Script for svg only fires after refresh

I have two clickable svg files on this wordpress page customized with CSS and JavaScript. The first svg (size: 447kb) loads without a problem and the script fires when clicked. The second svg loads a bit longer (size: 993kb) and .onclick only works if the page is refreshed.(Console says: Uncaught TypeError: Cannot set property ‘onclick’ of null)

After a lot of research I suspect this to be an Ajax issue. There is no option to deactivate Ajax so I tried following function to put the script into the footer:

function load_js_assets() {
    if( is_page(#) ) {
        wp_register_script('script', 'url/script.js', array( 'jquery' ), '0', false);
        wp_enqueue_script('script');
    } 
}

add_action('wp_enqueue_scripts', 'load_js_assets', 99999);

This didn’t do anything.

Within the script.js I tried window.onload, window.addEventListener("load", function(){}, document.load, document.addEventListener("DOMContentLoaded",…) nothing worked.

Currently my script goes like this:

window.addEventListener("load", function(){

(function() {
/*function for svg1*/
}; 
})();

(function(){
/*function for svg2*/
};
})();

});

Do I have any other options here please? (Please excuse my non-DRY way of coding, I’m still a noob)

75 thoughts on “Script for svg only fires after refresh”

  1. medicaments urologie produit medicamenteux pour maigrir , pharmacie en ligne que choisir pharmacie d’urgence ouverte , Modafinilo venta online, DГіnde comprar Modafinilo 200 mg. Comprar Modafinilo sin receta Comprar Modafinilo genГ©rico [url=https://kit.co/filmburpick/modafinilo-venta-online-barato-modafinilo-en-venezuela#]Modafinilo en farmacia Venezuela[/url] pharmacie bordeaux de garde Comprar Proventil inhalador genГ©rico, Comprar Proventil inhalador medicamento. Proventil inhalador en farmacia Colombia Comprar Proventil inhalador genГ©rico [url=https://kit.co/inizgroup/donde-comprar-proventil-inhalador-100-mcg-comprar-proventil-inhalador-generico#]DГіnde comprar Proventil inhalador 100 mcg[/url] , pharmacie de garde rueil therapie comportementale cognitive gard , medicaments klipal. pharmacie en ligne avis therapie jeux video DГіnde comprar Synthroid 100 mcg, Comprar Synthroid medicamento. Synthroid en farmacia Venezuela Comprar Synthroid genГ©rico [url=https://kit.co/langgogog/comprar-synthroid-medicamento-donde-comprar-synthroid-100-mcg#]DГіnde comprar Synthroid 100 mcg[/url] , pharmacie de garde aujourd’hui landes. pharmacie champagne argenteuil, pharmacie livraison boulogne billancourt pharmacie boulogne billancourt ouverte le soir . therapies ciblees, pharmacie de garde a marseille 13015 pharmacie horloge angers pharmacie de garde kochersberg .

    Reply

Leave a Comment