mergeAttributes method
Copies all attributes and its values from the specified element to the current element.
Syntax:
You can find the related objects in the Supported by objects section below.
Parameters:
Required. Reference to the source element that contains the attributes to be copied. | |||||||||||||||||||||||
Optional. Boolean that indicates whether the copying of the name and id attributes is forbidden or not.
One of the following values:
|
Return value:
This method has no return value.
Example HTML code 1:
This example illustrates the use of the mergeAttributes method:
|
||||
<head> <script type="text/javascript"> function CopyAttrs () { var source = document.getElementById ("source"); var destination = document.getElementById ("destination"); if (document.body.mergeAttributes) { // Internet Explorer destination.mergeAttributes (source, true); } else { // Firefox, Google Chrome, Safari, Opera for (var i=0; i < source.attributes.length; i++) { var attr = source.attributes[i]; var attrName = attr.name.toLowerCase (); if (attrName != "id" && attrName != "name") { destination.setAttribute (attr.name, attr.value); } } } } </script> </head> <body> <div id="source" style="background-color:yellow">Source element</div> <br /> <div id="destination" style="background-color:red">Destination element</div> <br /><br /> <button onclick="CopyAttrs ();">Copy the attributes of the source element to the destination element!</button> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
CommentNode
HTML elements:
a, abbr, acronym, address, applet, area, b, base, basefont, bdo, bgsound, big, blockquote, body, br, button, caption, center, cite, code, col, colgroup, comment, dd, del, dfn, dir, div, dl, dt, em, embed, fieldset, font, form, frame, frameset, h1, h2, h3, h4, h5, h6, head, hr, html, i, iframe, img, input:button, input:checkbox, input:file, input:hidden, input:image, input:password, input:radio, input:reset, input:submit, input:text, ins, isindex, kbd, label, legend, li, link, listing, map, marquee, menu, meta, nobr, noframes, noscript, object, ol, optgroup, option, p, param, plaintext, pre, q, rt, ruby, s, samp, script, select, small, span, strike, strong, style, sub, sup, table, tbody, td, textarea, tfoot, th, thead, title, tr, tt, u, ul, var, wbr, xml, xmp
Related pages:
External links:
User Contributed Comments