Search code examples
javascriptinnertext

Javascript function innerText


I want to get the innerText of "lid" but when I write "lid.innerText I get null values is there any other way.

function zoom() {
 var input = document.getElementById("myInput").value; //value from searchbox
// console.log(input);
 d3.json("intervals.json", function(alldata)  // entering json file  to look for oid
 {
    var i;
    for (i = 0; i < alldata.records.length; i++)  //for loop for getting the oid  alldata.records.length;
    {

      conceptid = alldata.records[i].oid;  //saving all the oid in conceptid
      lid = ("l" + conceptid.toString());  //concatenate with "l"
      console.log(lid);

      if (document.getElementById(lid).innerText === input)  // if lid.innertext = input
      {

        document.getElementById(lid).click();  //then zoom
      }

    }

 });
}


Solution

  • Your element is <text> which is a special tag inside <svg> so innerText does not apply. Use textContent instead:

      if (document.getElementById(lid).textContent === input)