Return to Snippet

Revision: 5571
at March 17, 2008 12:26 by localhorst


Initial Code
if (document.body.__defineGetter__) {

       if (HTMLElement) {

              var element = HTMLElement.prototype;

              if (element.__defineGetter__) {

                     element.__defineGetter__("outerHTML",

                           function () {

                                  var parent = this.parentNode;

                                  var el = document.createElement(parent.tagName);

                                  el.appendChild(this);

                                  var shtml = el.innerHTML;

                                  parent.appendChild(this);

                                  return shtml;

                           }

                     );

              }

       }

}

Initial URL
http://www.mohundro.com/blog/CommentView,guid,469f80ae-968d-4d60-ab5b-62a06bf045c5.aspx

Initial Description
This is a little trick I came up with to add outerHTML functionality in Firefox. For those who aren't familiar with outerHTML, it is an IE addition to the DOM that will return the element's HTML PLUS it's innerHTML. Is it really needed? No, but it can help with debugging sometimes.

Initial Title
outerHTML in Firefox

Initial Tags
DOM

Initial Language
JavaScript