outerHTML in Firefox


/ Published in: JavaScript
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  1. if (document.body.__defineGetter__) {
  2.  
  3. if (HTMLElement) {
  4.  
  5. var element = HTMLElement.prototype;
  6.  
  7. if (element.__defineGetter__) {
  8.  
  9. element.__defineGetter__("outerHTML",
  10.  
  11. function () {
  12.  
  13. var parent = this.parentNode;
  14.  
  15. var el = document.createElement(parent.tagName);
  16.  
  17. el.appendChild(this);
  18.  
  19. var shtml = el.innerHTML;
  20.  
  21. parent.appendChild(this);
  22.  
  23. return shtml;
  24.  
  25. }
  26.  
  27. );
  28.  
  29. }
  30.  
  31. }
  32.  
  33. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.