tags:

views:

20

answers:

1

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

I want to identify in the DOM the block 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

+1  A: 

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.

Nick Craver
Great, and here is a list of HTML block-level elements: http://htmlhelp.com/reference/html40/block.html - thanks Nick
Victor P