Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have an xml document that returns a list of map markers.

<markers>
<marker name="Marker 1 name" theid="100">
<content>Text goes here</content>
</marker>
<marker name="Marker 2 name" theid="101">
<content>Other text goes here</content>
</marker>
...
</markers>

I have some javascript to read through the list of markers and it successfully returns their attributes as variables like name and theid.

<script>
...
var xml = parseXml(data);
var markerNodes = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markerNodes.length; i++) {
var name = markerNodes[i].getAttribute("name");
var theid = markerNodes[i].getAttribute("theid");
var content = markerNodes[i].getElementsByTagName("content");
...
</script>

However I cannot get the javascript to return the contents of the element tag content. In place of the text content I get the message [object HTMLCollection]. Would anyone be kind enough to help me fix this please?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

The bit I was missing was textContent:

var content = markerNodes[i].getElementsByTagName("content")[0].textContent;

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.