从DOMContentLoaded事件访问DOM?

时间:2010-11-16 18:45:59

标签: jquery dom firefox-addon

有没有办法从DOMContentLoaded

触发的事件中访问DOM
window.addEventListener("load", function() { myExtension.init(); }, false);

var myExtension = {
  init: function() {
    var appcontent = document.getElementById("appcontent");   // browser
    if(appcontent)
      appcontent.addEventListener("DOMContentLoaded", myExtension.onPageLoad, true);
  },

  onPageLoad: function(aEvent) {
     //how to access to the DOM from aEvent??
  }, 
}

来自https://developer.mozilla.org/en/Code_snippets/On_page_load

1 个答案:

答案 0 :(得分:1)

您链接到的页面上onPageLoad的第一行显示了如何:

var doc = aEvent.originalTarget; // doc is document that triggered "onload" event

这会为您提供网站的document元素。