Is it possible to fire an event when d3js is ready?

I am currently adding all javascript files to HTML <head>after uglying and using these jquery functions to check if the document is ready

$( document ).ready(function() {}); OR $(function() {});

Is it possible to fire an event when d3js is ready? (e.g. cordova deviceReady)

I want to remove jquery, at present I am dependent only on the two jquery functions listed above, and also triggering an event will help to initialize the data set in several files

+4
source share
2 answers

Of course, you can do this with this snippet.

document.addEventListener("DOMContentLoaded", function(e) {
   /* Your D3.js here */
  });

Or you can just put all your JS code at the bottom of the tag body.

+3
source

load. - :

var script= document.createElement('script'),
    loadHandler = function () {
        // code to be executed after script is loaded
    };
script.src = '/d3.js'; // path to script
script.addEventListener('load', loadHandler);
document.head.appendChild(script);
Hide result
+2

Source: https://habr.com/ru/post/1621786/


All Articles