I have been working on a Element.toHTML function, and added two
methods to the Element object. And I was looking for any insight about
my code. Please, feel free to comment. Thanks.
start
html
head
/head
body
div id=container
div id=test_div style=border: 1px solid blue;
div id=foo_divBar !/div
/div
/div
script type=text/javascript src=prototype.js/script
script type=text/javascript
Element.addMethods( {
toHTML: function(element) {
if (typeof element=='string') element = $(element); // IE needs
that check with XML
return Try.these(
function() {
var xmlSerializer = new XMLSerializer();
return element.nodeType == 4 ? element.nodeValue :
xmlSerializer.serializeToString(element);
},
function() {
return element.xml || element.outerHTML || $
(element).clone().wrap().up().innerHTML;
}
) || '';
},
getStyles: function(element) {
element = $(element);
return $A(element.style).inject({}, function(styles, styleName) {
styles[styleName.camelize()] = element.getStyle( styleName );
return styles;
} );
},
clone: function(element) {
var clone = new Element(element.tagName);
$A(element.attributes).each(function(attribute) { if
( attribute.name != 'style' ) clone[attribute.name] =
attribute.value; });
clone.setStyle( element.getStyles() );
clone.update(element.innerHTML);
return clone;
} } );
alert( $('test_div').toHTML() );
$('container').appendChild( $('test_div').clone() );
$('container').appendChild( $('test_div').clone() );
$('container').appendChild( $('test_div').clone() );
/script
/body
/html
end --
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
Prototype: Core group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/prototype-core?hl=en
-~--~~~~--~~--~--~---