Answer the question
In order to leave comments, you need to log in
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
You can also use iframe
to 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("...");
You need to place this line through innerHTML
in some element (possible with display: none
). For example:
document.getElementById("hidden-div").innerHTML = myStr;
After that, it document.getElementById("...")
will find elements from myStr
.
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 questionAsk a Question
731 491 924 answers to any question