Notes for XML Element operations

Source: Internet
Author: User

In IE, if the version is earlier than 9, you cannot directly set Custom Attributes. You must use the setattribute method. other browsers do not have this problem.

 
// For example, sizzleCodeAn error occurs in ie xml. You cannot directly use el. AAA = "BBB" If (parent & (parent [expando]! = Donename |! ELEM. nodeindex) {COUNT = 0; For (node = parent. firstchild; node = node. nextsibling) {If (node. nodetype = 1) {node. nodeindex = ++ count ;}} parent [expando] = donename ;}

XML getelementsbytagname. If the tag name has a namespace (separated by ":" In other words), opera, chrome, and Safari cannot be found. Firefox and IE can be used. In this case, you need to use the getelementsbytagnamens and lookupnamespaceuri APIs. The following describes how to find the tagname:

Function getelementsbytagname (tagname, Els, flag_xml) {VaR method = "getelementsbytagname", elems = [], uniqresult = {}, prefix if (flag_xml & tagname. indexof (":")> 0 & els. length & els [0]. lookupnamespaceuri) {var arr = tagname. split (":"); prefix = arr [0]; tagname = arr [1]; method = "getelementsbytagnamens"; prefix = els [0]. lookupnamespaceuri (prefix);} switch (els. length) {Case 0: Return ELEM S; Case 1: // In ie67, if an input element with name length exists, the following all. Length returns this element, instead of the length value var all = prefix? Els [0] [Method] (prefix, tagname): els [0] [Method] (tagname) for (VAR I = 0, rI = 0, El; el = All [I ++];) {If (El. nodetype = 1) {// prevents mixed comments node elems [ri ++] = El} return elems; default: for (I = 0, rI = 0; el = els [I ++];) {var nodes = prefix? El [Method] (prefix, tagname): El [Method] (tagname) for (var j = 0, node; node = nodes [J ++];) {var uid = Dom. getuid (node); If (! Uniqresult [uid]) {uniqresult [uid] = elems [ri ++] = node ;}} return elems ;}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.