I have written this jquery code :
<script type="text/javascript">
$(document).ready(function () {
var university = { title: 0, href: 1, link: 2 };
var universities = [];
$(".aname").each(function (key, value) {
university.href = value.all[0].href;
university.title = value.all[0].innerHTML;
university.link = value.parentNode.all[2].all[0];
universities[key] = university;
});
debugger; // now if you watch universities this only last item.
});
</script>
It should save all university objects in to array of universities it works but it replace only the last item in to all items after $.each I don’t know why?
How about:
However, I don’t think the
allcollection is cross-browser. In that case, consider replacing it by jQuery’s traversing methods, or native ones. For instance, ifall[0]selects the first child (does it?), then you can writethis.children[0]or$( this ).children( ':first' ).