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.
精彩评论