xml - Select a node that has a specific attribute value in javascript -


in xml :

<elements>         <product id="1">                 <brand>xxxxxxx</brand>                 <dci>xxxxx</dci>                 <therapeutic_area>xxxxxx</therapeutic_area>         </product>         <product id="2">                 <brand>xxxxxx</brand>                 <dci>xxxx</dci>                 <therapeutic_area>xxxx</therapeutic_area>         </product>         <product id="3">                 <brand>xxx</brand>                 <dci>xxxx</dci>                 <therapeutic_area>xxxxx</therapeutic_area>         </product> 

i need select node has specific attribute value. instance 2

i tried not work:

alert(xmldoc.getelementsbytagname("product")[0].getattributenode("2")); 

thanks in advance help

try

var list=xmldoc.getelementsbytagname("product"); (i=0;i<list.length;i++) {      if(list[i].getattribute("id")==2){         // found node      } }  

Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -