tags:

views:

48

answers:

2

I have a large html file of a story.

The <p> tags are not closed, for example:

<p> First paragraph
<p> Second paragraph

I would like to have a proper XHTML document:

<p> First paragraph</p>
<p> Second paragraph</p>

Can I achieve this with jQuery?

Thanks

+2  A: 

No.

jQuery operates on a DOM, and the DOM doesn't care about tags, only elements (which it is fed by a parser that does care).

You probably want to use something like HTML Tidy to convert from HTML to XHTML if you really need XHTML.

David Dorward
A: 

Are you looking to persist the changes made to the file? If the answer to that is yes then the answer to your question is no. jQuery is used to manipulate the DOM, not the HTML document/file that was parsed in order to construct the DOM in the first place.

I would recommend a HTML parser to do this (you may be able to also do this with regular expressions, depending on the complexity of the document). There may be some simpler tools out there that will convert a HTML document to an XHTML document without needing to get ones hands dirty with code at all.

Russ Cam