La propiedad de sólo lectura NonDocumentTypeChildNode.nextElementSibling retorna el elemento inmediátamente posterior al especificado, dentro de la lista de elementos hijos de su padre, o bien null si el elemento especificado es el último en dicha lista.
Sintaxis
var nextNode = elementNodeReference.nextElementSibling;
Ejemplo
<div id="div-01">Este es div-01</div>
<div id="div-02">Este es div-02</div>
<script type="text/javascript">
var el = document.getElementById('div-01').nextElementSibling;
console.log('Subsiguientes de div-01:');
while (el) {
console.log(el.nodeName);
el = el.nextElementSibling;
}
</script>
Este ejemplo muestra en la consola lo siguiente cuando se carga:
Subsiguientes de div-01: DIV SCRIPT
Polyfill para Internet Explorer 8
Esta propiedad no está soportada con anterioridad a IE9, así que el siguiente fragmento de código puede utilizarse para añadir el soporte a IE8:
// Source: https://github.com/Alhadis/Snippets/blob/master/js/polyfills/IE8-child-elements.js
if(!("nextElementSibling" in document.documentElement)){
Object.defineProperty(Element.prototype, "nextElementSibling", {
get: function(){
var e = this.nextSibling;
while(e && 1 !== e.nodeType)
e = e.nextSibling;
return e;
}
});
}
Especificación
| Especificación | Estado | Observaciones |
|---|---|---|
| DOM The definition of 'ChildNodenextElementSibling' in that specification. |
Living Standard | Se dividió la interfaz ElementTraversal en ChildNode, ParentNode, y NonDocumentTypeChildNode. Este método queda ahora definido en la primera.Los interfaces Element y CharacterData implementaron el nuevo interfaz. |
| Element Traversal Specification The definition of 'ElementTraversal.nextElementSibling' in that specification. |
Recommendation | Añadió su definición inicial al interfaz puro ElementTraversal y su uso en Element. |
Compatibilidad con navegadores
| Prestación | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
Soporte básico (en Element) |
4 | 3.5 (1.9.1) | 9 | 9.8 | 4 |
Soporte en CharacterData |
29.0 | 25 (25) [1] | No support | 16.0 | No support |
| Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|
Soporte básico (en Element) |
(Yes) | 1.0 (1.9.1) | (Yes) | 9.8 | (Yes) |
Soporte en CharacterData |
(Yes) | 25.0 (25) | No support | 16.0 | No support |
[1] Firefox 25 añadió también esta propiedad a DocumentType, y fue eliminada en Firefox 28 debido a problemas de compatibilidad.
Ver también
- El interfaz puro
ChildNode. - Tipos de objetos que implementan este interfaz puro:
CharacterData,Element, yDocumentType.
Etiquetas y colaboradores del documento
Colaboradores en esta página:
Grijander81
Última actualización por:
Grijander81,