I'm trying to manipulate some anchors after the document is loaded to alter their href attribute using Prototype. Based on the class of an anchor, its href has to be rewritten to be used by a tracking software.
I hacked some things together but can't quite figure out why it doesn't work. It always returns undefined, not matter what I search for.
<script type="text/javascript">
var elements = $$(".replace");
for (el in elements) {
el.href = "other_href.html";
}
</script>
<a href="this_href.html" class="replace">Link</a>
When I alert(el)
in the loop, it returns either undefined or (when I search for a.replace
an extraordinary number of elements that don't even exist on my page.
Where is my thinking error in here?