1

The below code works in IE but not in other browsers.

var node = xmlHttp.responseXML.documentElement;
var eitems = node.getElementsByTagName("nib:ProcessRequestResponse");
txt = eitems.context.text;
txt2 = txt.replace("\n", "");

Gives error "eitems.context is undefined". I have also tried eitems.context.textContent, eitems.context.innertext, eitems.context.innerHTML. All gives same error.

Keertika
  • 59
  • 6

2 Answers2

0

getElementsByTagName() returns a HTMLCollection. Access the first element with

 var item = eitems.item(0);

or just

 var item = eitems[0];

Use item to get the content.

Knut Herrmann
  • 30,880
  • 4
  • 31
  • 67
  • eitems.item(0) gives null and eitems[0] gives undefined. I need the complete content of the tag "nib:ProcessRequestResponse". eitems.length displays 0 in both IE and other browsers. But eitems.context.text gives the content of the tag in IE where as in other browsers it gives "undefined". – Keertika Sep 16 '21 at 15:12
  • What returns getElementsByTagName()? – Knut Herrmann Sep 16 '21 at 15:14
  • node.getElementsByTagName("nib:ProcessRequestResponse") returns [object HTMLCollection] – Keertika Sep 16 '21 at 16:34
  • What is the output of `console.log(JSON.stringify(Array.from(eitems)))`? – Knut Herrmann Sep 16 '21 at 17:44
0

I used txt = node.textContent to get the content of tag and it worked

Keertika
  • 59
  • 6
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 16 '21 at 13:52