TIPS: solve the problem that "FF cannot read outerHTML", ffouterhtml
The DOM attribute outerHTML can be used in IE, Opera, google Chorme, and other browsers, but Firefox does not support this attribute. Although this attribute is not commonly used, however, we still need to use some applications, so it is necessary to implement the outerHTML function under FF.
After reading some articles on the Internet, the most typical method should be throughDefineSetter,DefineGetterTo extend this attribute for the DOM attribute. The specific implementation is to traverse the attributes and subnodes of the read element, and then assemble the html string by yourself. For details, refer to this article: firefox does not have an outerHTML solution. In this article, outerHTML reads and writes are complete.
The method of assembling HTML strings to obtain outerHTML values is a bit troublesome. You can see a solution on the Internet, and the code is concise, it can also be used in various browsers. The principle is: Create a div element, and put the cloned object of the element to be read into this div, and read the childNode of this div. The sample code is as follows:
Document. createElement ("DIV "). appendChild (htmlNode. cloneNode (true )). parentNode. innerHTML) document. createElement ("DIV "). appendChild (htmlNode. cloneNode (true )). parentNode. innerHTML)
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.