--- title: ChildNode.before() slug: Web/API/ChildNode/before tags: - API - DOM - Experimental - Nodo - Referencia - metodo translation_of: Web/API/ChildNode/before ---
[Throws, Unscopable] void ChildNode.before((Node or DOMString)... nodes);
nodos
var parent = document.createElement("div"); var child = document.createElement("p"); parent.appendChild(child); var span = document.createElement("span"); child.before(span); console.log(parent.outerHTML); // "<div><span></span><p></p></div>"
var parent = document.createElement("div"); var child = document.createElement("p"); parent.appendChild(child); child.before("Text"); console.log(parent.outerHTML); // "<div>Text<p></p></div>"
var parent = document.createElement("div"); var child = document.createElement("p"); parent.appendChild(child); var span = document.createElement("span"); child.before(span, "Text"); console.log(parent.outerHTML); // "<div><span></span>Text<p></p></div>"
ChildNode.before()
es unscopableEl método before () no está definido en la declaración with. Consulte {{jsxref ( "Symbol.unscopables")}} para obtener más información.
with(node) { before("foo"); } // ReferenceError: before is not defined
Especificación | Estado | Comentario |
---|---|---|
{{SpecName('DOM WHATWG', '#dom-childnode-before', 'ChildNode.before()')}} | {{Spec2('DOM WHATWG')}} | Definición Inicial. |
{{CompatibilityTable}}
Función | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Soporte Básico | {{CompatChrome(54.0)}} | {{CompatGeckoDesktop(49)}} | {{CompatUnknown}} | {{CompatOpera(39)}} | {{CompatUnknown}} |
Función | Android | Android Webview | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|
Soporte Básico | {{CompatNo}} | {{CompatChrome(54.0)}} | {{CompatGeckoMobile(49)}} | {{CompatUnknown}} | {{CompatOpera(39)}} | {{CompatUnknown}} | {{CompatChrome(54.0)}} |