Ver Mensaje Individual
  #1 (permalink)  
Antiguo 22/07/2009, 04:36
Protegon
 
Fecha de Ingreso: mayo-2007
Mensajes: 12
Antigüedad: 17 años
Puntos: 0
InnerHtml en vez de textnode ¿cómo hacerlo?

Esto funciona perfectamente:

Código:
<script type="text/javascript">
function addtext(what){
if (document.createTextNode){
var mytext=document.createTextNode(what)
document.getElementById("mydiv").appendChild(mytext)
}
}
</script>
<div id="mydiv" onClick="addtext('This Text was added to the DIV')" style="font:20px bold; cursor:hand">Click here for example</div>
pero yo necesito que esto quede exactamente igual con la diferencia de poder insertar html en la parte donde dice This Text was added to the DIV para poder hacer esto:
Código:
<script type="text/javascript">
function addtext(what){
if (document.createTextNode){
var mytext=document.createTextNode(what)
document.getElementById("mydiv").appendChild(mytext)
}
}
</script>
<div id="mydiv" onClick="addtext('<img src="LINK DE LA IMÁGEN" />"')" style="font:20px bold; cursor:hand">Click here for example</div>
Intenté haciendo esto:

Código:
<script type="text/javascript">
function addtext(what){
if (document.innerHTML){
var mytext=document.innerHTML(what)
document.getElementById("mydiv").appendChild(mytext)
}
}
</script>
<div id="mydiv" onClick="addtext(' This Text was added to the DIV.<br /> adasda')" style="font:20px bold; cursor:hand">Click here for example</div>
solo reemplazando el

Podrían ayudarme con esto de transformar el createTextNode por el innerHTML pero no me ha servido de nada.

gracias de antemano.