Gulp DOMJS

by David Joseph Guzsik

HTML

<p><img src="…" alt=""/></p>
<p><h1>…</h1></p>
<p align="center"><em>…</em></p>
<h2 id="heading-1-">Heading 1</h2>
<p>…</p>
<p>…</p>
<h2 id="attributions">Attributions</h2>
<p>
    <strong>…</strong> <a href="…">….</a>, <a href="…">…</a><br>
    <strong>…</strong> <a href="…">…</a><br>
    <strong>…</strong> <em>…</em> … <a href="…">…</a><br>
    <strong>…</strong> … <a href="…">…</a>
</p>
<ul>
    <li>
        <a href="…">…</a>
    </li>
    …
</ul>
<p>
    <a href="…">…</a>
</p>
<h2 id="heading-2-">Heading 2</h2>
<p>
    <a href="…">…</a>
</p>

JavaScript

var el = document.getElementById('attributions'),
    newElements = "",
    i = 0,
    allow = 'ulp';

while (el.nextSibling !== null && el.nextSibling.nodeName.toLowerCase() !== 'h2'){
   	console.log(el.nextSibling);
    if (allow.indexOf(el.nextSibling.nodeName.toLowerCase()) !== -1)
    	newElements += el.nextSibling.outerHTML+'\n';
    el = el.nextSibling;
}

console.log(newElements);