Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

scarenci

Remoção do createElement ????

Recommended Posts

Olá Pessoal,

 

 

Eu andei tentando de tudo para deletar o código criado abaixo mas não consegui !!!! Se alguém puder ajudar eu agradeço!!!!

function telefoneFixoWrite(){

//document.getElementById("tab_fixo").parentNode.removeChild (document.getElementById("linha1"));

//document.getElementById("tab_fixo").deleteRow (document.getElementById("linha1").rowIndex);

document.getElementById("tab_fixo").style.visibility = 'visible';

 

for(var i=0 ; i < tamanhoFixo ; i++){

 

var novoPaisFixo = document.createElement("input"); //<input type='text' name='paisFixo'"+i+"' value='51' size='2'>

novoPaisFixo.name = "paisFixo"+i;

novoPaisFixo.type = "text";

novoPaisFixo.value = "51";

novoPaisFixo.size = "6";

 

var novoEstadoFixo = document.createElement("input"); //<input type='text' name='estadoFixo"+i+"' value='35' size='2'>

novoEstadoFixo.name = "estadoFixo"+i;

novoEstadoFixo.type = "text";

novoEstadoFixo.value = "35";

novoEstadoFixo.size = "8";

 

var novofixo = document.createElement("input"); //<input type='text' name='fixo"+i+"'>

novofixo.name = "fixo"+i;

novofixo.type = "text";

novofixo.value = "";

novofixo.size = "10";

 

//<input type="button" onClick="removeElement();" value="clear">

var clear = document.createElement("input"); //<input type='text' name='fixo"+i+"'>

clear.name = "fixo"+i;

clear.type = "button";

clear.value = "Excluir";

clear.setAttribute('onClick','removeElement(this)');

 

var tabLinha = document.createElement("tr");

 

var tabColuna1 = document.createElement("td");

tabColuna1.appendChild(novoPaisFixo);

 

var tabColuna2 = document.createElement("td");

tabColuna2.appendChild(novoEstadoFixo);

 

var tabColuna3 = document.createElement("td");

tabColuna3.appendChild(novofixo);

 

var tabColuna4 = document.createElement("td");

tabColuna4.appendChild(clear);

 

tabLinha.appendChild(tabColuna1);

tabLinha.appendChild(tabColuna2);

tabLinha.appendChild(tabColuna3);

tabLinha.appendChild(tabColuna4);

 

tabBody = document.getElementById("tab_body");

 

tabBody.appendChild(tabLinha);

}

 

}

function removeElement(divNum) {

alert("pelo menos entrou");

 

var d = document.getElementById("tab_body");

var olddiv = document.getElementById(divNum);

// d.removeChild(olddiv);

d.parentNode.removeChild(olddiv);

}

 

Agradeço desde já qualquer ajuda

Compartilhar este post


Link para o post
Compartilhar em outros sites

Teste esse código:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pt-br" lang="pt-br"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Adicionando e removendo elementos dinamicamente</title><script type="text/javascript">//<![CDATA[function preencheLista(){	var tabela 	= document.getElementById("tBody-lista");	var ultima 	= tabela.rows.length;	var linha 	= document.createElement("tr");	linha.setAttribute("id","line"+ultima);		var celula1 	= document.createElement("td");	var nodotexto1 	= document.createTextNode("teste"+ultima);	celula1.appendChild(nodotexto1);	linha.appendChild(celula1);		var celula2 	= document.createElement("td");	var nodotexto2 	= document.createTextNode("teste"+ultima);	celula2.appendChild(nodotexto2);	linha.appendChild(celula2);		var celula3 	= document.createElement("td");	var nodotexto3 	= document.createTextNode("teste"+ultima);	celula3.appendChild(nodotexto3);	linha.appendChild(celula3);		var celula4 	= document.createElement("td");	var link		= document.createElement('a');	link.setAttribute('href','javascript: void(0)');	link.setAttribute('title','Apagar');	link.setAttribute('rel','line'+ultima);	link.className	= 'link';	link.onclick	= function()	{		document.getElementById("tBody-lista").removeChild(document.getElementById(this.getAttribute("rel")));	};	var texto 		= document.createTextNode("Apagar");	link.appendChild(texto);	celula4.appendChild(link);	linha.appendChild(celula4);	tabela.appendChild(linha);}//]]></script></head><body><input type="button" value="Adicionar" onclick="preencheLista()" /><br /><br /><table border="1px">	<thead>		<tr>			<td>Teste</td><td>Teste</td><td>Teste</td><td>Teste</td>		</tr>	</thead>	<tbody id="tBody-lista">	</tbody></table></body></html>

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.