jquery .ready() equivalent in d3js?

纵饮孤独 提交于 2020-06-10 08:43:48

问题


currently i am adding all javascript at HTML <head> after uglying as file & using these jquery functions to check document ready

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

is there any d3js equivalent to remove using of these jquery functions ?


回答1:


A

You can simply put the <script> tag at the bottom of the body tag.

B

you can add the DOMContentLoaded event and insert your d3js code inside.

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

Direct Answer

There is no equivalent to the jQuery function in the D3.js library, the snippet written above will work as well.




回答2:


There is no specific d3 way but,

if your javascript is below any of the html elements then the dom is loaded before it starts executing the javascript.

Putting your javascript at the bottom of the body is usually good enough. You can also use native js method which works in most of the browsers.

document.addEventListener("DOMContentLoaded", function(event) { 
  //do work
});


来源:https://stackoverflow.com/questions/34469877/jquery-ready-equivalent-in-d3js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!