M
Miroslav Stampar [MCSD.NET / Security+]
what am i doing wrong. i want to attach onclick event to links. i am
using code below but it doesn't work as it should. plz help.
<html>
<head>
<title>getElementById example</title>
</head>
<body>
<div id="here">
<td>
<a href ="http://www.google.com">Google</a>
<a href ="http://www.yahoo.com">Yahoo</a>
</td>
</div>
<script>
var elementDiv = document.getElementById('here');
var elementsA = elementDiv.getElementsByTagName('a');
for(var i=0;i<elementsA.length;i++)
{
elementsA.onclick="alert('BLA')";
alert(elementsA.href);
}
</script>
</body>
</html>
p.s.
I want to do this:
<html>
<body>
<a href="http://www.google.com" onclick="alert('BLA')">Google</a>
</body>
</html>
THANKS IN ADVANCE
using code below but it doesn't work as it should. plz help.
<html>
<head>
<title>getElementById example</title>
</head>
<body>
<div id="here">
<td>
<a href ="http://www.google.com">Google</a>
<a href ="http://www.yahoo.com">Yahoo</a>
</td>
</div>
<script>
var elementDiv = document.getElementById('here');
var elementsA = elementDiv.getElementsByTagName('a');
for(var i=0;i<elementsA.length;i++)
{
elementsA.onclick="alert('BLA')";
alert(elementsA.href);
}
</script>
</body>
</html>
p.s.
I want to do this:
<html>
<body>
<a href="http://www.google.com" onclick="alert('BLA')">Google</a>
</body>
</html>
THANKS IN ADVANCE