HTML and CSS Reference
In-Depth Information
Figure 15.22 Before the cloning takes place.
Figure 15.23 The user clicks the button and the first paragraph has been cloned.
Cloning a Node Attribute. The next example uses cloning to set an attribute for an
element, in this case the style attribute. If the same attribute already exists for that node,
it will be replaced with the new attribute.
FORMAT
setAttributeNode(referenceToAttribute)
EXAMPLE
var p1Style=p1.getAttributeNode("style");
var cloneP1Style=p1Style.cloneNode(mode);
p2.setAttributeNode(cloneP1Style);
EXAMPLE 15.13
<html>
<head><title>Attributes and Nodes</title>
<script type="text/javascript">
1
function stylePara(mode) {
2
var p1 = document.getElementById("para1");
var p2 = document.getElementById("para2");
3
var p1Style=p1.getAttributeNode("style");
4
var cloneP1Style=p1Style.cloneNode(mode);
5
p2.setAttributeNode(cloneP1Style);
}
Search WWH ::




Custom Search