Error: Can not read property 'style' of null

1

I'm doing a work in html, css, javascript and ajax and the goal is to change the tab style with the id of the sensor name when it is clicked, but says that the element does not exist and wanted to know what error it I'm committing.

I'm basically importing from an xml file and putting the tabs with the name of the sensor name of the xml file inside a tag named list_sensors

        strHtmlNomes = "";
        for(i = 0; i < nomesSensores.length; i++)
        {
            nomeSensor = nomesSensores[i];
            strHtmlNomes +='<div><a href="#" id="'+nomeSensor+'" class="tablinks" onclick="openSensor('+nomeSensor+')">'+nomeSensor+'</a></div>';       
        }



        document.getElementById("list_sensores").innerHTML = strHtmlNomes;

and before closing the html I have this javascript script

function openSensor(nomeSensor){
    document.getElementById(nomeSensor).style.color = "blue";
}

    
asked by anonymous 02.10.2016 / 14:31

1 answer

1

If your ID is numeric, also add some letter.

Change the assignment of the variable nomeSensor to:

nomeSensor = "sensor_" + nomesSensores[i];

source: link

    
02.10.2016 / 14:43