* Loop over all of the attributes on the target node and make sure the * original DOM node has the same attributes. If an attribute * found on the original node is not on the new node then remove it from * the original node * @param {HTMLElement} fromNode * @param {HTMLElement} toNode
(fromNode, toNode)
| 1324 | * @param {HTMLElement} toNode |
| 1325 | */ |
| 1326 | function morphAttrs(fromNode, toNode) { |
| 1327 | var attrs = toNode.attributes; |
| 1328 | var i; |
| 1329 | var attr; |
| 1330 | var attrName; |
| 1331 | var attrValue; |
| 1332 | var foundAttrs = {}; |
| 1333 | |
| 1334 | for (i=attrs.length-1; i>=0; i--) { |
| 1335 | attr = attrs[i]; |
| 1336 | if (attr.specified !== false) { |
| 1337 | attrName = attr.name; |
| 1338 | attrValue = attr.value; |
| 1339 | foundAttrs[attrName] = true; |
| 1340 | |
| 1341 | if (fromNode.getAttribute(attrName) !== attrValue) { |
| 1342 | fromNode.setAttribute(attrName, attrValue); |
| 1343 | } |
| 1344 | } |
| 1345 | } |
| 1346 | |
| 1347 | // Delete any extra attributes found on the original DOM element that weren't |
| 1348 | // found on the target element. |
| 1349 | attrs = fromNode.attributes; |
| 1350 | |
| 1351 | for (i=attrs.length-1; i>=0; i--) { |
| 1352 | attr = attrs[i]; |
| 1353 | if (attr.specified !== false) { |
| 1354 | attrName = attr.name; |
| 1355 | if (!foundAttrs.hasOwnProperty(attrName)) { |
| 1356 | fromNode.removeAttribute(attrName); |
| 1357 | } |
| 1358 | } |
| 1359 | } |
| 1360 | } |
| 1361 | |
| 1362 | /** |
| 1363 | * Copies the children of one DOM element to another DOM element |