1
I am doing a work in html, css, javascript and ajax and the goal is to change the style of the tab with the sensor name id when it is clicked, but it says that the element does not exist and I wanted to know what mistake I am making.
Basically I am importing from an xml file and placing tabs with the sensor id of the xml file inside a tag with the name list_sensores
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 html I have this javascript script
function openSensor(nomeSensor){
document.getElementById(nomeSensor).style.color = "blue";
}
the variableName is never numerical
– Daniel Dias
Does the name repeat in some cases, or are they just unique names? Spaces are used in the name assigned to the id?
– wmarquardt
the name is always unico <sensor id="1"> <name>Temperature</name> <Description>Temperature sensor</Description> </sensor> <sensor id="2"> <name>Quality_do_ar</name> <Description>Air quality sensor</Description> </sensor> </sensor> <sensor id="3"> <name>Fluxo_de_transito</name> <Description>Traffic flow sensor</Description> </sensor> <sensor id="4"> <name>Activities_cardiaca</name> <Description>Heart activity sensor installed on people</Description> </sensor>
– Daniel Dias
html id is with sensor name not with number, sensor list is xml file
– Daniel Dias
Maybe it’s your parameter
onclick
, as you are passing a string as argument to its function, try putting it in HTML like this:onclick="openSensor(\'' + nomeSensor + '\')">'
– wmarquardt