View Full Version : How to extract a certain div from responseText

03-09-2009, 04:18 PM
I am just about javascript newbie, so please bear with me!

I have the following code which I use to fetch an external file and place it within a div tag on current page.

At the moment, the code successfully fetches the entire file, but I would like to alter it to fetch only a certain div tag from the file, let's say <div id="mydivtag">

How can I achieve this?

Thanks in advance!

mnmxmlhttp = new myXMLHttpRequest ();
if (mnmxmlhttp) {
mnmxmlhttp.open ("POST", url, true);
mnmxmlhttp.setRequestHeader ('Content-Type',

mnmxmlhttp.send (content);
errormatch = new RegExp ("^ERROR:");

target2 = document.getElementById (divcontent);

mnmxmlhttp.onreadystatechange = function () {
if (mnmxmlhttp.readyState == 4) {
mnmString = mnmxmlhttp.responseText;

if (mnmString.match (errormatch)) {
mnmString = mnmString.substring (6, mnmString.length);
target = document.getElementById (divcontent);
target2.innerHTML = mnmString;
} else {
target = document.getElementById (divcontent);
target2.innerHTML = mnmString;


03-09-2009, 04:40 PM
The file has to be fetched, opened and read somewhere.
If you don't want to do it in the client, you'll have to do it on the server,
by posting the requirements (the url and and the desired return) to a server script.

03-09-2009, 04:48 PM

I would rather have it written in the client, and then fetch the div tag from it...

How can I write responseText to a client?