开发者

Close <p> tags in jQuery

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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜