How to parse HTML from XMLHttpRequest in Javascript

SaswatPadhi's Avatar, Join Date: May 2009
~ Б0ЯИ Τ0 С0δЭ ~
Hi all,

I hope JS experts can help me with this one.

I accept a web-page(HTML) using XMLHttpRequest. Then, I want to parse the HTML, so that I can access the DOM tree of the page.
Can anyone help me with this ?

I have tried doing it like :

Code: JavaScript
var data = XHR.responseText;
var myDiv = document.createElement("div");

myDiv.innerHTML = data.replace(/<script(.|\s)*?\/script>/g, '');

Then I try doing things like :
Code: JavaScript
myDiv.getElementsByTagName("table");
but they fail.

Thanx

Saswat
pradeep's Avatar, Join Date: Apr 2005
Team Leader
You can try using jQuery which has an amazing selector functionality.
SaswatPadhi like this
SaswatPadhi's Avatar, Join Date: May 2009
~ Б0ЯИ Τ0 С0δЭ ~
Thanx pradeep