Нафиг это ваше jquery.
<div>
<h1>title</h1>
</div>
<h2>title</h2>
<script>
var nodes = document.getElementsByTagName('*'), i = nodes.length;
var el = document.querySelector('h2'), findTag = 'H1';
while(i--) if(nodes[i] === el) break;
while(i--) if(nodes[i].tagName === findTag) break;
if(nodes[i]) nodes[i].style.color='#f00';
</script>
<div>
<h1>title</h1>
</div>
<div>
<h2>title</h2>
</div>
<script>
var nodes = document.getElementsByTagName('*'), i = nodes.length;
var el = document.querySelector('h2'), findTag = 'H1';
while(i--) if(nodes[i] === el) break;
while(i--) if(nodes[i].tagName === findTag) break;
if(nodes[i]) nodes[i].style.color='#f00';
</script>
<h1>title</h1>
<div>
<h2>title</h2>
</div>
<script>
var nodes = document.getElementsByTagName('*'), i = nodes.length;
var el = document.querySelector('h2'), findTag = 'H1';
while(i--) if(nodes[i] === el) break;
while(i--) if(nodes[i].tagName === findTag) break;
if(nodes[i]) nodes[i].style.color='#f00';
</script>
<h1>title</h1>
<h2>title</h2>
<script>
var nodes = document.getElementsByTagName('*'), i = nodes.length;
var el = document.querySelector('h2'), findTag = 'H1';
while(i--) if(nodes[i] === el) break;
while(i--) if(nodes[i].tagName === findTag) break;
if(nodes[i]) nodes[i].style.color='#f00';
</script>
<div>
<h1>title</h1>
</div>
<div>
<h1>title</h1>
</div>
<div>
<h2>title</h2>
</div>
<script>
var nodes = document.getElementsByTagName('*'), i = nodes.length;
var el = document.querySelector('h2'), findTag = 'H1';
while(i--) if(nodes[i] === el) break;
while(i--) if(nodes[i].tagName === findTag) break;
if(nodes[i]) nodes[i].style.color='#f00';
</script>
<div>
<h1>title</h1>
<h1>title</h1>
</div>
<div>
<h1>title</h1>
<h1>title</h1>
</div>
<div>
<h1>title</h1>
</div>
<div>
<h2>title</h2>
</div>
<script>
var nodes = document.getElementsByTagName('*'), i = nodes.length;
var el = document.querySelector('h2'), findTag = 'H1';
while(i--) if(nodes[i] === el) break;
while(i--) if(nodes[i].tagName === findTag) break;
if(nodes[i]) nodes[i].style.color='#f00';
</script>