SO fiddle
Test Fiddle mainly for SO Questions
HTML
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/dot-luv/jquery-ui.css">
<div class="section"><h1>This is a .section</h1><p>This was already here</p></div>
<div class="not-a-section"><h1>This isn't a .section</h1><p>This was already here</p></div>
<div class="section"><h1>This is a .section</h1><p>This was already here</p></div>
CSS
div { margin:10px; }
h1 { font-weight:bold; }
JavaScript
// Get all header elements
var header = document.getElementsByTagName('h1'),
parent,
newP,
text;
// Loop through the elements
for (var i=0, m = header.length; i < m; i++) {
parent = header[i].parentNode;
// Check for "section" in the parent's classname
if (/(?:^|\s)section(?:\s|$)/i.test(parent.className)) {
newP = document.createElement("p");
text = document.createTextNode('This paragraph was inserted with JavaScript');
newP.appendChild(text);
// Insert the new P element after the header element in its parent node
parent.insertBefore(newP, header[i].nextSibling);
}
}