spacer
Yehuda Shiran May 18, 2000
Merging Objects with Perseverance
Tips: May 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

The mergeAttributes() method copies all read/write attributes to the specified element. In Internet Explorer 5.0 and earlier, the syntax is as follows:

<targetObject>.mergeAttribute(sourceObject);
The parameter, sourceObject, is the object from which we copy the attributes to the object that invokes mergeAttributes(), <targetObject>, and is required. The targetObject's attributes having the same name as the sourceObject's attributes are preserved and are not overwritten. In Internet Explorer 5.0 and earlier, attributes that are read only, such as ID, are not merged. The mergeAttribute() method copies attributes, events, and styles.

The following example shows the usage of the mergeAttributes() as is supported by IE 5.0 and earlier:

<HTML>
<HEAD>
<SCRIPT>
<!--
function mergeObjects() {
  object2.mergeAttributes(object1);
  alert(object2.outerHTML);
}
//-->
</SCRIPT>
</HEAD>
<BODY>
  <DIV ID="object1" ATTRIBUTE1="true" ATTRIBUTE2="true"
    onclick="alert('click');" onmouseover="this.style.color='#0000FF';"
    onmouseout="this.style.color='#000000';">
    This is a sample <b>DIV</b> element.
  </DIV>
  <DIV ID="object2">
    This is another sample <b>DIV</b> element.
  </DIV><BR>
  <INPUT TYPE="button" VALUE="Merge Attributes" onclick="mergeObjects()">
</BODY>
</HTML>

Move your mouse over the next two DIV elements. Notice the color change when you go over the top element. The top one supports the onmouseover, onmouseout, and onclick event handlers, while the bottom one does not. Now, click the "Merge Attributes" button below, and check again the two DIV elements above. Notice that the bottom DIV now has all the event handlers and attributes that the top one has. As a further proof, you also get an alert box with the HTML description of the bottom element. Again, you can notice all the elements and handlers that the top one has.

This is a sample DIV element.
This is another sample DIV element.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business