Chris a écrit :
document.getElementById('id').getElementsByTagName('a')
this works for the first link I wrap in a tag with an id but not the
rest e.g.
<div id="tooltipthis"><a href="" title="">link</a></div>
<a href="" title="">No tooltip</a>
<div id="tooltipthis"><a href="" title="">link</a></div>
this html is wrong : ID can only be unique
CSS :
=====
div { height: 500px; margin: 20px; border: 1px solid }
HTML :
======
<div id="tooltipthis_1">
<a href="#tooltipthis_3" title="">link 1</a>
</div>
<a href="#" title="">No tooltip</a>
<div id="tooltipthis_2">
<a href="#" title="">link 2</a>
</div>
<div id="tooltipthis_3">
<a href="#tooltipthis_1" title="">link 3</a>
</div>
JS :
====
function getLinks(commonId) {
var d = document.getElementsByTagName('DIV');
var L = [];
for(var i=, S=d.length; i<S; i++)
{
if(S
.id &&
S.id.indexOf(commonId)>=0 &&
S.getElementsByTagName('A') &&
S.getElementsByTagName('A').length>0)
{
var A = S.getElementsByTagName('A');
for(var k=0, Z=A.length; k<A; k++)
{
L[L.length] = A[k];
}
}
}
return L;
}
window.onload = function() { var T = getLinks('tooltipthis'); };
HTML example of using :
=======================
<button onclick="location = T[0].href;">
click first link of tooltipthis
</button>