This is only finding the first link. Why is it not looping through all of the links?
http://jsfiddle.net/infatti/7r4fV/
var alertHref = $('#myLinks').find('a').attr('href');
$('#myDivs').find(alertHref).css('background-color', 'yellow');
<span id="myLinks">
<a href="#div1">link 1</a>
<a href="#div2">link 2</a>
</span>
<hr />
<div id="myDivs">
<div id="div1">div 1</div>
<div id="div2">div 2</div>
</div>