HTML and CSS Reference
EXAMPLE 15.13 ( CONTINUED )
<p id="para1" style ="font-family: cursive ;
The news is so fabulous, I need to shout it out again! You
won the lottery!<br />
<p id="para2"> I like your style, not what you say.
value="Clone me" />
The purpose of the stylePara() function is to copy the style of a paragraph where
style is an attribute of the first paragraph. (To set the class attribute use the class-
First we need to get a reference to both paragraphs, the one with the style attribute
set, and the one without it.
Next we use the getAttributeNode() method to get a reference to the style attribute
for the first paragraph. The returned reference is assigned to p1Style .
This cloning step creates a replica of the style attribute of the first paragraph.
The setAttributeNode() method sets the style attribute for the second paragraph.
The style for the first paragraph is assigned to the style attribute. This is the attri-
bute that will be cloned and set for the second paragraph.
When the user clicks this button, the function stylePara() will be called with an
argument of false. In this example the program works the same way whether you
send true or false as the mode. Figures 15.24 and 15.25 show the results.
Figure 15.24 Cloning a style attribute—before clone.