HTML and CSS Reference
In-Depth Information
• after : this adds content after each element, making the new content the next sibling of the
original element. If we had used this in the example above, the span would occur after the
closing label tag.
• before : this is similar to after , except the new element will appear before the original
element. If we had used this in the example above, the span would have appeared immedi-
ately before the label element.
• prepend : this creates a new child element at the start of the element (as opposed to ap-
pend which created the child at the end of the element). If we had used this in the example
above, the * would have appeared to the left of the label text, but the span would still be a
child of the label .
• remove : this completely removes an element from the document. You can use this to re-
move the newly added span elements.
replaceWith : this
replaces an element or set of elements with a new element or set of
elements.
In the examples above we have been adding content to existing elements. Instead of adding
content to elements, it is also possible to create content and add it to elements. For instance,
the following is a valid jQuery call:
> $('<span>*</span>')
This returns the element specified by the HTML, although obviously that element is not
part of the DOM at this point. It is then possible to call manipulation functions to add this
element to the document:
> $('<span>*</span>').appendTo('label')
This will append a * as a child element to each label in the document. This approach can
also used with the following functions:
• insertBefore : this function includes the new elements as siblings of the specified element
or elements, but places them before them in the DOM.
• insertAfter : this function includes the new elements as siblings of the specified element
or elements, but places them after them in the DOM.
• prependTo : this function includes the new elements as children of the specified element
or elements, but places them at the start of the element, making them the first children.
The element inserted in this manner can be any HTML element or set of elements, includ-
ing elements selected from the document.
Search WWH ::




Custom Search