Ver Mensaje Individual
  #3 (permalink)  
Antiguo 07/01/2012, 20:51
Avatar de dual3nigma
dual3nigma
Colaborador
 
Fecha de Ingreso: febrero-2010
Ubicación: Ciudad de México
Mensajes: 295
Antigüedad: 14 años, 1 mes
Puntos: 122
Respuesta: Estructura del DOM para elementos b i u como hijos de p cuando hay texto?

Hola LhaN,

En realidad es así:

Código Texto:
Ver original
  1. p
  2. +-- texto: Un texto que tiene
  3. +-- b
  4. |    +-- texto: negritas
  5. +-- texto: y tambien tiene
  6. +-- i
  7.      +-- texto: cursivas

Miralo tu mismo

Código HTML:
Ver original
  1.     <title></title>
  2.  
  3.  
  4. </head>
  5.  
  6. <p>Un texto que tiene <b>negritas</b> y tambien tiene <i>cursivas</i></p>
  7.  
  8.  
  9.     var parrafo = document.body.getElementsByTagName('p')[0];
  10.  
  11.     console.log(parrafo.firstChild); // Text: Un texto que tiene
  12.     console.log(parrafo.firstChild.nextSibling); // HTMLElement
  13.     console.log(parrafo.firstChild.nextSibling.nextSibling); // Text: y tambien tiene
  14.     console.log(parrafo.firstChild.nextSibling.nextSibling.nextSibling); // HTMLElement
  15.  
  16. </body>
Te recomiendo mucho https://developer.mozilla.org/en/Gecko_DOM_Reference

Saludos!