N
N
Nikita Permin2012-05-26 12:11:07
JavaScript
Nikita Permin, 2012-05-26 12:11:07

String in dom, how?

Hello. There is an HTML page in the form of a string obtained using XMLHttpRequest'a. How can I get myStr.getElementById('')… to work? or rather, what is the correct way to convert it so that this method works?

ps The first attempt to make a gadget for Win7. The snippet from developer.mozilla.org/En/Code_snippets :HTML_to_DOM doesn't work. HTMLParser does not contain the .createDocument method,

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
Nesvet, 2012-05-26
@NekitoSP

You can also use iframeto separate DOM trees and eliminate the match id. Here, for example, I threw a function: Then like this:
function subDocument(string) {
    var iframe = document.createElement("iframe");
    iframe.style.display = "none";
    document.body.appendChild(iframe);
    iframe.contentDocument.body.innerHTML = string;
    return iframe.contentDocument
};

var newDocument = subDocument(myStr);
newDocument.getElementById("...");

N
Nesvet, 2012-05-26
@Nesvet

You need to place this line through innerHTMLin some element (possible with display: none). For example:
​document.getElementById("hidden-div").innerHTML = myStr;
After that, it document.getElementById("...")will find elements from myStr.

A
Anton Bobylev, 2012-05-26
@dpigo

If you want to completely separate the entities, you can still like this: jsfiddle.net/75bwJ/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question