I'm a jQuery newbie doing some cargo-cult programming in a Trac template. Please forgive the stupid question.
Trac 1.0.1 (and likely other versions) has a preview feature which uses jQuery.replaceWith()
to put new elements -- not just new values -- into a ticket header. Unfortunately, I have a Trac plugin which controls the visibility of elements by setting their display and replaceWith()
creates new elements and doesn't copy their attributes. Ideally, I'd have a jQuery function that copied contents from one set of elements to another so I could update the existing elements in place. But something that copies attributes to the new elements would be OK, too. Is this possible?
Let's say I have (all it ORIG) is:
<tr id='x'>
<td display='none'>ABCD</td>
</tr>
and what I get from the server to update that (call it NEW) is:
<tr id='x'>
<td>QRST</td>
</tr>
After replace with, I end up with my page containing the second snippet. What I want (call it MERGED) is:
<tr id='x'>
<td display='none'>QRST</td>
</tr>
The code that does this today is:
$("#ticket").replaceWith(items.filter('#ticket'));
Where I've ended up is:
function copyHeaderData(f, t) {
if (f.length != t.length) {
console.log('Shape mismatch');
}
else {
var i;
for (i = 0; i < t.length; ++i) {
t[i].innerHTML = f[i].innerHTML;
}
}
}
// Update ticket box
copyHeaderData(items.filter("#ticket").find("td"), $("#ticket td"));