Go4Expert

Go4Expert (http://www.go4expert.com/)
-   JavaScript and AJAX (http://www.go4expert.com/forums/javascript/)
-   -   How to parse HTML from XMLHttpRequest in Javascript (http://www.go4expert.com/forums/parse-html-xmlhttprequest-javascript-t19198/)

SaswatPadhi 27Aug2009 19:37

How to parse HTML from XMLHttpRequest in Javascript
 
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 4Sep2009 11:38

Re: How to parse HTML from XMLHttpRequest in Javascript
 
You can try using jQuery which has an amazing selector functionality.

SaswatPadhi 4Sep2009 11:54

Re: How to parse HTML from XMLHttpRequest in Javascript
 
Thanx pradeep :)


All times are GMT +5.5. The time now is 18:49.