开发者

Identify HTML block elements in jQuery

I have simple one column HTML files (ebooks from Gutenberg Project).

I want to identify in the DOM the bloc开发者_如何学编程k elements (like <h1> <p> <div> <table> etc, not <a> <em> <b> etc) and enclose them in <div> tags.

Is there any easy way to do it in jQuery?

Thanks


You can use a selector for the elements elements you want and call .wrap() for each, like this:

$("h1, p, div, table").wrap("<div></div>");

This would wrap each one in a <div> individually. It looks from your example page they use a known set of elements, so just add whichever one you want to the selector.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜