That's part of the W3C DOM spec, it's called cloneNode.

var empty_thingee = getElement("thingee").cloneNode(false);

-bob

On Dec 2, 2005, at 6:55 AM, John Watson wrote:

This leads me to a feature request.  I find myself, when replacing an
element, having to just copy the class and id off of it before
swapping it.  It would be nice if there were some sort of method to
take an element, scrape the id and class information off of it and
return an element of the same type with the original elements id and
class.

So, if I have something like this in the page:
<div id="thingee" class="fancy dancy"><h1>stuff here</h1><h2>other
stuff</h2></div>
and I had a handle to the 'thingee' div, I could get back and element
which looked like:
<div id="thingee" class="fancy dancy"></div>
with a simple method call.

John.

p.s. if this already exists, point me to the docs, and I'll shut right up. :)


On 12/1/05, Bob Ippolito <[EMAIL PROTECTED]> wrote:


On Dec 1, 2005, at 7:49 PM, dbdweeb wrote:


I'm trying to coordinate the dynamic contents of a one select input
based on the value of another. 'userselect' populates on page load and
'tblselect' populates fine the first time a userselect item is
selected
but it doesn't get refreshed with subsequent selects. Why not? Here's
the code:

You forgot to set the id on the new SELECT nodes.  After it's swapped
out the first time, there's no longer any nodes in the document with
an id of "tblselect".

Below is a slight refactoring that works.  Additionally, it replaces
the select nodes with invisible divs so that it's obvious when
something is loading, doesn't depend on any server, and uses
MochiKit.Logging for debugging/error reporting.

-bob

<html><head>
<script src="../MochiKit/MochiKit.js" type="text/javascript"></ script>
<script type="text/javascript">

function opt_display(row) {
     return OPTION({"value": row[0]}, row[1]);
};

function showSelectData(result) {
     var mydata = concat([[-1, '--']], result["data"]);
     logDebug(repr(mydata));
     var html_select = SELECT(
         {"id": "userselect", "onchange": "popTables(this.value);"},
         map(opt_display, mydata)
     );
     swapDOM("userselect", html_select);
};

function showSelectData2(result) {
     var mydata = concat([[-1, '--']], result["data"]);
     logDebug(repr(mydata));
     var html_select = SELECT({"id": "tblselect"}, map(opt_display,
mydata));
     swapDOM("tblselect", html_select);
};

function showError(e) {
     logError(map(function (kv) {
         return "\n    " + kv.join(": ");
     }, sorted(items(e))).join(""));
     logger.debuggingBookmarklet();
}

function popTables(ownerName) {
     var url = "./" + ownerName
     //var d = loadJSONDoc(url);
     swapDOM("tblselect", DIV({"id": "tblselect"}));
     var d = wait(0.5, {data: [[ownerName, ownerName], ["baz",
"wibble"]]});
     d.addCallback(showSelectData2);
     d.addErrback(showError);
};

addLoadEvent(function () {
     //var d = loadJSONDoc("./getUsers");
     var d = wait(0.5, {data: [["getUsers", "getUsers"], ["foo",
"bar"]]});
     d.addCallback(showSelectData);
     d.addErrback(showError);
});
</script>
</head>
<body>
<div id="userselect"></div>
<div id="tblselect"></div>
</body></html>


Reply via email to