I'm not 100% sure if i understand your question completely, but i'll try to give my 2 cents.
My approach doesn't help you getting an element from a different xul file from the one you are using, i don't really know even if that is possible.
What i usually do when i want to use a big elements multiple times, like when i want to create for example richlistboxitems, what i do is:
I create a template for the items:
<richlistbox id="richlistbox"/>
<richlistitem id="richListItemTemplate" hidden="true">
<listcell class="classOne" label="one" width="50"/>
<listcell class="classTwo" label="two" width="80"/>
</richlistitem>
Note that i have the template hidden.
Then when i load the panel or page that contains the richlistbox, i dynamically fill them out doing:
for(var i = 0; i < elements.length; i++) {
var item = document.getElementById("richListItemTemplate").cloneNode(true);
item.removeAttribute("id");
item.removeAttribute("hidden");
item.getElementsByClassName("classOne")[0].setAttribute("label",elements.value);
item.getElementsByClassName("classTwo")[0].setAttribute("label",elements.value);
document.getElementById("richlistbox").appendChild(item);
}
This way you are cloning the original element, removing the id, but you can access it's child elements through className that is unique inside that element.
Maybe you can do the same to your button.
You create a buttonTemplate
with id="myButtonTemplate"
and hidden="true"
, and when you want to append it to an element, you do a buttonTemplate.cloneNode(true) (true because you want all the child elements), you customize it the way you want and then append it to the element that you want.
Hope this helps you.