0

I want a javascript code which will go through all the html file in my root folder and sub-folders and gets the content which are within a particular tag, eg:

<div id="content">
!!this content!!
</div>

It should check for a comment at the top of html and only get the content if it exist.

<!--Allowed-->

It should only get if this is there. First of all is this possible? I wish jquery could do this!

Update: Got enlightened that javascript is for client-side! So One last question, how does you use php to get the content that is within the a particular tag?

    <div id="content">
    !!this content!!
    </div>

4 Answers 4

2

At first you have to get all the folders that are in the folder (on the server). That's not possible with JavaScript alone. You have to write a PHP (or any other web-language supported on your webspace/server) which gives you the filename-list. Then you can load each file with jQuery's ajax-functions and test for your comment, etc.

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

4 Comments

"That's not possible with JavaScript " That is not entirely true.
I'm aware of that, but I don't expect him to use server-side JS.
Oh..I forgot that entirely!!! Server side and Client side!! But just out of curiosity does all server support server side js?
I never really used server-side JS myself, but as far as I know: no.
0

Javascript has no access to the file system. You need a server side language to do that.

2 Comments

"Javascript has no access to the file system. " Not necessarily true. See other posts.
Note that the question says "...from HTML", not server side javascript. :)
0

No it is not possible with javascript. It is a client side scripting language. You need a serverside scripting language like PHP. Check out http://php.net/ look up the fopen(), include(), and dir() functions.

Comments

-1

If you know the exact content of the comment you're searching for, try this:

if(document.documentElement.innerHTML.indexOf('<!--Comment-->') > 0){
    //voila!
}

If not, you can use regular expressions to parse the text. I'm not an expert in regex, so i can't say i can help you there.
Of course, this will only work on a per-page basis, it won't browse your file system. For that you should have a server-side language.
Hope this helps

Comments

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.