+2  A: 

From the W3C website about id's (http://www.w3.org/TR/REC-html40/struct/global.html#h-7.5.2):

This attribute assigns a name to an element. This name must be unique in a document.

In other words, give the second span another id to fix it.

Mythica
But I need the span to have the same identification. class would be ok. But how do I update class with ajax?
Johan
It's generally not advisable to use the same id more than once. Updating elements by class can be done by iterating over the dom and by inspecting the class. Easier is to use for instance jQuery and do something like $(".yourClass").html(response);
Mythica
+2  A: 

Change the id= to class= because 2 elements with the same id is WRONG

Then either using jQuery and its powerful selectors, or here's a function some guy wrote to get all elements by class name

David Archer
A: 

Well, you could use the NAME attribute. It is perfectly valid to have multiple nodes with the same NAME.

So you would have these nodes:

<span id="somethingUnique1" name="tumme"></span>
<span id="somethingUnique2" name="tumme"></span>

To update them, you would do something like:

var nodes = document.getElementsByName("tumme");
for (var i = 0, node; node = nodes[i]; i++) {
  node.innerHTML = xmlHttp.responseText;
}
jhurshman
And you don't really need the IDs on the spans for this; I just put that in for kicks.
jhurshman
While it is valid for multiple elements to have the same name, is it INVALID for a span to have any name at all.
David Dorward
@David Archer: You are not. There is no concept of an array in HTML.
David Dorward
sorry @David Dorward, I deleted my comment. True, but I was coming from a human-readable point of view. e.g mutliple elements in a form with same name will be posted as an array, won't they?
David Archer
It's true that it doesn't validate for a span to have a NAME attribute, but it is works well, consistently, and speedily in all major browsers.I am a pragmatist about such things.
jhurshman
Yes, it works fine :)But it does not validate. And it would be great if it did.
Johan
@David Archer: No. Multiple elements with the same name will be posted as a serialised string containing the same token before an equals sign twice. This MIGHT be converted to an array when it is de-serialised.
David Dorward
@jhurshman Ah. The pragmatism of depending on undocumented behaviour in software from multiple vendors. I'll stick to class attributes.
David Dorward
@David Dorward, thanks for clearing that up. :-)
David Archer
+1  A: 

Since an id must be unique per document, you cannot have two elements with the same id. Find some other way to identify the elements. A class is the standard means to mark an element as a member of a group. You could also give them different ids and then store those ids in an array.

<span class="tumme"> 4 </span>

Then when you get the data from your XHR request back, find all the elements and loop over them. While you can roll your own method for getting elements by class name, it is easier to use an existing one.

Looping over them will be just a case of:

for (var i = 0; i < elements.length; i++) {
    elements[i].innerHTML = xmlHttp.responseText;
}
David Dorward
I think the problem here is that he needs to know how to find all those elements
David Archer
@David Archer: Umm. Read my answer again. I suggest two ways to identify the elements, and describe how to get them in each case.
David Dorward
A: 

Use getElementsByClass:

function getElementsByClass(searchClass,node,tag) { var classElements = new Array(); if ( node == null ) node = document; if ( tag == null ) tag = '*'; var els = node.getElementsByTagName(tag); var elsLen = els.length; var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)"); for (i = 0, j = 0; i < elsLen; i++) { if ( pattern.test(els[i].className) ) { classElements[j] = els[i]; j++; } } return classElements; }

xav0989