What is the equivalent of .before() in Javascript?
node.insertBefore()
is pretty much the equivalent : https://developer.mozilla.org/en-US/docs/Web/API/Node.insertBefore
$('#id').before('something');
//equivalent
var node = document.getElementById('id');
node.parentNode.insertBefore('something', node);
Here what jQuery does : https://gist.github.com/kagagnon/a13de27760ba1af883c0#file-gistfile1-js-L6064
before: function() {
return this.domManip( arguments, function( elem ) {
if ( this.parentNode ) {
this.parentNode.insertBefore( elem, this );
}
});
}
you can use insertBefore
in javascript
node.insertBefore(newnode, existingchild);
The example above will append newnode as a child of node, directly before the existingchild node.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With