How can I separate in sections a document with headings?
Convert this
<h1>chapter 1</h1>
<p>lorem ipsum</p>
<p>sit amet</p>
<h1>chapter 2</h1>
<p>lorem ipsum</p>
<p>sit amet</p>
into this
<div class="chapter">
<h1>chapter 1</h1>
<p>lorem ipsum</p>
<p>sit amet</p>
</div>
<div class="chapter">
<h1>chapter 2</h1>
<p>lorem ipsum</p>
<p>sit amet</p>
</div>
I guess with jQuery this is easy, but I haven't figured how yet.
The div tag defines a section or division within a HTML file. It typically contains headings, paragraphs, tables or other elements that need to be grouped together. Commonly used with css by setting the <div class="?"> attribute to set the look and feel of a section of your web page.
Just move #header-middle last in your HTML. Then what is float: right will go right, float: left will go left, and the middle content will fill upwards and occupy the unclaimed middle space. What is happening the way you have it, is the unfloated element is pushing the floated element after it.
The <section> tag defines a section in a document.
Sectioning elements can be nested inside one another as many times as is needed based on the content. The header and footer in a sectioning element can also contain sectioning elements.
Try something like this:
$('h1').each( function(){
$(this).nextUntil('h1').andSelf().wrapAll('<div class="chapter">');
});
Example: http://jsfiddle.net/redler/YVF2w/
I guess with jQuery this is easy, but I haven't figured how yet.
Don't do this with jQuery. Write this into your HTML, or use whatever view / template engine your using to write your HTML like this.
Also there is such a thing as <section>
and <header>
I would recommend using them (but since they are HTML5 you might need html5 shim).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With