1

I got to read a number of HTML files, get its tags content and generate a report using these contents (e.g day1.html has Simon, I need to read day1.html file, and get 'author' div content which is 'Simon' and generate my own report using this data). How can I do it using Javascript? any help is highly appreciated. Many thanks. An

4
  • 1
    Client-side JavaScript accessing HTML files on a web-server, or server-side JavaScript accessing files from the file system, or...? Commented Dec 10, 2012 at 4:33
  • it is server-side java script. yesterday my friend suggested me using AJAX, still working on searching :( Commented Dec 11, 2012 at 3:11
  • If it's server-side JS (node.js?) you wouldn't use Ajax: Ajax is a way for JS in the browser to make a request to the web-server without reloading the current page. Is a request from a web browser involved at all in your requirement? Commented Dec 11, 2012 at 3:49
  • My problem is: I am about to make news blog page for my project, We have a html(or xml) file called "blog.html(or .xml)", this file defines title, author, content for each post of the blog(like <DIV id="author">Simon</DIV> <DIV id="title">New blog</DIV> <DIV id="content">Content bla bla bla</DIV> , webadmin can also update this file later). My job is to read this file, get details and out put to jsp page. many thanks for your reply :) Commented Dec 11, 2012 at 4:56

1 Answer 1

1

If you're not adverse to using jQuery you can use get() to load and parse an HTML document via JavaScript:

jQuery.get('day1.html', function(html)) {
  var author_div_text_content = jQuery('DIV#author', html).text(); 
}

A sample working on the jsFiddle web site:

http://jsfiddle.net/KCxDp/

Sign up to request clarification or add additional context in comments.

1 Comment

I ll try to work on this way you showed me, yesterday my friend suggested me using ajax and I am still googling it. maybe yr method would work out.many tks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.