Estoy tratando de reemplazar el valor de etiqueta de estilo en línea de un elemento. El elemento actual es el siguiente:eliminación de estilos de elemento html a través de javascript
`<tr class="row-even" style="background: red none repeat scroll 0% 0%; position: relative; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" id="0000ph2009-06-10s1s02">`
y me gustaría quitar todas esas cosas estilo para que se labró por su clase en lugar de su estilo en línea. He intentado eliminar element.style; y element.style = null; y element.style = ""; en vano. Mi código actual se rompe en esta declaración. La función entera se parece a:
función unSetHighlight (índice) {
if(index < 10)
index = "000" + (index);
else if (index < 100)
index = "000" + (index);
else if(index < 1000)
index = "0" + (index);
if(index >= 1000)
index = index;
var mainElm = document.getElementById('active_playlist');
var elmIndex = "";
for(var currElm = mainElm.firstChild; currElm !== null; currElm = currElm.nextSibling){
if(currElm.nodeType === 1){
var elementId = currElm.getAttribute("id");
if(elementId.match(/\b\d{4}/)){
elmIndex = elementId.substr(0,4);
if(elmIndex == index){
var that = currElm;
//that.style.background = position: relative;
}
}
}
}
clearInterval(highlight);
alert("cleared Interval");
that.style.background = null;
alert("unSet highlight called");
}
la clearInterval funciona, pero la alerta nunca se dispara y el fondo sigue siendo el mismo. ¿Alguien ve algún problema? Gracias de antemano ...
function unSetHighlight(index){
alert(index);
if(index < 10)
index = "000" + (index);
else if (index < 100)
index = "000" + (index);
else if(index < 1000)
index = "0" + (index);
if(index >= 1000)
index = index;
var mainElm = document.getElementById('active_playlist');
var elmIndex = "";
for(var currElm = mainElm.firstChild; currElm !== null; currElm = currElm.nextSibling){
if(currElm.nodeType === 1){
var elementId = currElm.getAttribute("id");
if(elementId.match(/\b\d{4}/)){
elmIndex = elementId.substr(0,4);
alert("elmIndex = " + elmIndex + "index = " + index);
if(elmIndex === index){
var that = currElm;
alert("match found");
}
}
}
}
clearInterval(highlight);
alert("cleared Interval");
that.removeAttribute("style");
//that.style.position = "relative";
//reColor();
alert("unSet highlight called");
}
Probado removeAttribute ("estilo"), sigue sin suerte. Estoy usando setInterval para recorrer los colores de fondo para (intentar) crear un efecto de pulso. Trataré de escribir algunas otras clases de estilo para intentar responder 4. ¿Alguna otra idea? Mi código actual se publica a continuación ... – danwoods
sería genial si aceptaras [this] (http://stackoverflow.com/a/1040439/2008111) como la respuesta correcta a esta pregunta – caramba
^No es la respuesta correcta , aunque. –