getElementsByClassName returns [] instead of asynchronous appended node

后端 未结 6 1884
野性不改
野性不改 2020-12-17 05:40

(I ask my question again after the first one was terribly formulated)

I face the following problem:

6条回答
  •  时光取名叫无心
    2020-12-17 06:32

    Here's a way to do it for Firefox, Opera, Chrome and Safari. Basically, you just do div.innerHTML = div.innerHTML to reinterpret its content as HTML, which will make that class attribute from the XML file be treated as an HTML class name.

    
    
        
            
            
            
        
        
            

    Remove the this.status === 200 if you're testing locally in browsers that support xhr locally.

    The importNode() function doesn't seem to work in IE (9 for example). I get a vague "interface not supported" error.

    You could also do it this way:

    var doc = this.responseXML;
    var markup = (new XMLSerializer()).serializeToString(doc.getElementsByTagName("response")[0].getElementsByTagName("div")[0]);
    div.innerHTML = markup;
    

    as long as the markup is HTML-friendly as far as end tags for empty elements are concerned.

提交回复
热议问题