Inserts the specified element into the parent of the before element if not already present. If parent already
contains child, this method does nothing.
342928
public static void lazyInsertBefore(Element newElement, Element before) {
        if (!before.parentNode.contains(newElement)) {
            before.parentNode.insertBefore(newElement, before);
        }
    }
135417
def before(self, *nodes: Union[AbstractNode, str]) -> None:
        
        if self.parentNode:
            node = _to_node_list(nodes)
            self.parentNode.insertBefore(node, self)
672669
function (node, preceding) {
            var next = preceding.nextSibling, parent = preceding.parentNode;
            if (next) {
                parent.insertBefore(node, next);
            } else {
                parent.appendChild(node);
            }
            return node;
        }
333904
def _replace_element_by_own_content(self, element):
        
        # pylint: disable=no-self-use

        if element.has_children_elements():
            children = element.get_children_elements()
            for child in children:
                element.insert_before(child)
            element.remove_node()
        elif element.has_children():
            element.replace_node(element.get_first_node_child())
1103192
function insert_child_before(Frame $new_child, Frame $ref, $update_node = true) {
    if ( $ref === $this->_first_child ) {
      $this->prepend_child($new_child, $update_node);
      return;
    }

    if ( is_null($ref) ) {
      $this->append_child($new_child, $update_node);
      return;
    }
    
    if ( $ref->_parent !== $this )
      throw new DOMPDF_Exception("Reference child is not a child of this node.");

    // Update the node    
    if ( $update_node )
      $this->_node->insertBefore($new_child->_node, $ref->_node);

    // Remove the child from its parent
    if ( $new_child->_parent )
      $new_child->_parent->remove_child($new_child, false);
    
    $new_child->_parent = $this;
    $new_child->_next_sibling = $ref;
    $new_child->_prev_sibling = $ref->_prev_sibling;

    if ( $ref->_prev_sibling )
      $ref->_prev_sibling->_next_sibling = $new_child;
    
    $ref->_prev_sibling = $new_child;
  }
789250
function () {
        var self = this;

        if (self[0] && self[0].parentNode) {
          return domManipulate(self, arguments, function (node) {
            this.parentNode.insertBefore(node, this);
          });
        }

        return self;
      }
769763
function ( child, index ) {
            var el = this.element();
            if ( typeof index === 'number' ) {
                var children = el.children,
                    childNum = children.length;
    
                if ( childNum > 0 && index < childNum ) {
                    el.insertBefore( child, children[index] );
                    return;
                }
            }
            el.appendChild( child );
        }
259901
public void insertParentAfter(Node node) throws ChildNodeException {
    if (node != null) {
      // give this node my children
      node.setFirstChild(getFirstChild());

      setFirstChild(null); // clear our list
      addChild(node);      // make our child
    }
  }
1124677
def append(self, child):
        
        if self._can_add_child(child):
            if self.element == child.parent:
                self._remove_from_traversal_index(child)
                self.list.append(child)
                try:
                    self.indexes[child.name].append(child)
                except KeyError:
                    self.indexes[child.name] = [child]
            elif self.element == child.traversal_parent:
                try:
                    self.traversal_indexes[child.name].append(child)
                except KeyError:
                    self.traversal_indexes[child.name] = [child]
1359887
public E insert(E element) {
        E evicted = null;
        if (size() >= capacity) {
            if (evictPolicy == EvictPolicy.REJECT_NEW) {
                // reject the new element
                return element;
            }
            // Evict first, so we do not need to resize
            evicted = evict();
        }
        deque.offerLast(element);
        return evicted;
    }
580451
def add_tag_before(tag_name, tag_text, parent_tag, before_tag_name):
    
    new_tag = Element(tag_name)
    new_tag.text = tag_text
    if get_first_element_index(parent_tag, before_tag_name):
        parent_tag.insert( get_first_element_index(parent_tag, before_tag_name) - 1, new_tag)
    return parent_tag
1323444
def insert_child(self, i, child):
        
        child.parent = self
        self.children.insert(i, child)
        self.changed()
574392
public void insertAsPrevious(BasicDoubleLinkedNode<V> node) {

    if (this.previous != null) {
      this.previous.setNext(node);
      node.previous = this.previous;
    }
    node.setNext(this);
    this.previous = node;
  }
745743
function(node, position) {
	position = position || 'before';

	if( position == 'before'  ) {
		this._node.parentNode.insertBefore(node._node, this._node);
	} else if ( position == 'after' ) {
		this._node.parentNode.insertBefore(node._node, this.next() ? this.next()._node : null);
	}
}
780704
function insertAt(parent, index, html) {
  console.log('inserting at ' + index + ' ' + html);
  console.log(parent);
  if (index === 0)
    return parent.prepend(html);
  parent.children(':nth-child(' + index + ')').after(html);
}
55870
function after(element, content) {
  if (isString(content)) {
    return element.insertAdjacentHTML('afterEnd', content);
  } else {
    // when the second parameter of 'insertBefore' is 'null' the content is
    // appended to the end of the 'parentNode'.
    return element.parentNode.insertBefore(normalizeContent(content), element.nextSibling);
  }
}
245740
def set_parent(self, parent):
        
        if self._parent == parent:
            return
        if self._parent:
            self._parent.remove_child(self)
        self._parent = parent
        if parent:
            parent.add_child(self)