I created a basic markup file with a simple div element like this: <div id="container" /> How can I create a new button, change lets say id and style:x and add it to the container from script
In general, structural changes to the DOM will require a re-load via document.load. First you add the node using the W3C DOM APIs, then you reload the document. Something like this:
the example above works fine if you only want to update the DOM once. But i am changing the DOM of the initial xmu-file in two steps, which removes the first changes.
1 step: I am adding new elements to the DOM and do a document.load() at the end. 2 step: I am adding even more elements and do a document.load() at the end.
Surprisingly, all elements i've created in step 1) are missing aftere the second document.load(). What is going on here
I would have expected that document.load() would lead to a refreshed view of the DOM that is currently in memory. But it seems that document.load() rather reloads the initial xmu-file and just adds the changes that were made directly before the call of document.load().
Could someone please give me more details on this topic or suggest a workaround.
How to create button in Script
David Sadler
In general, structural changes to the DOM will require a re-load via document.load. First you add the node using the W3C DOM APIs, then you reload the document. Something like this:
CORE_NS = "http://www.dvdforum.org/2005/ihd";var STYLE_NS = "http://www.dvdforum.org/2005/ihd#style";
var btn = document.createElementNS(CORE_NS, "button");
btn.setAttribute("id", "dynamic");
btn.setAttributeNS(STYLE_NS, "position", "absolute");
btn.setAttributeNS(STYLE_NS, "x", "500px");
btn.setAttributeNS(STYLE_NS, "y", "500px");
btn.setAttributeNS(STYLE_NS, "width", "500px");
btn.setAttributeNS(STYLE_NS, "height", "500px");
btn.setAttributeNS(STYLE_NS, "backgroundColor", "red");
document.container.appendChild(btn);
document.load();
PeterTPeterT
the example above works fine if you only want to update the DOM once.
But i am changing the DOM of the initial xmu-file in two steps, which removes the first changes.
1 step: I am adding new elements to the DOM and do a document.load() at the end.
2 step: I am adding even more elements and do a document.load() at the end.
Surprisingly, all elements i've created in step 1) are missing aftere the second document.load().
What is going on here
I would have expected that document.load() would lead to a refreshed view of the DOM that is currently in memory. But it seems that document.load() rather reloads the initial xmu-file and just adds the changes that were made directly before the call of document.load().
Could someone please give me more details on this topic or suggest a workaround.
Thanks in advance,
Bjorn