Skip to content
This repository was archived by the owner on Mar 2, 2020. It is now read-only.

Inserting Content

dev-nicolaos edited this page Apr 11, 2019 · 2 revisions

FSLDOM provides four functions for inserting content into the DOM.

  • before()
  • prepend()
  • append()
  • after()

These functions are built on top of element.insertAdjacentElement and element.insertAdjacentHTML and correspond to the position values 'beforebegin', 'afterbegin', 'beforeend', and 'afterend' respectively.

Syntax

fD.insertionFunction(target, newContent)

  • { HTMLElement OR string } target - The element relative to which the new content will be placed, or selector string that can be used in document.querySelector() to retrieve said element.
  • { HTMLElement OR string } newContent - The content to be added, either an HTML Element or a string of HTML
Return Value

Returns a Boolean value indicating whether or not the content was successfully injected.

Examples

Add list item to end of list

  fD.append(myList, '<li>Yet another item</li>');

Add banner notification under header

  fD.after('#site-header', bannerElement);

Check for successful injection

  if (fD.before(myMap, myLegend)) {
    // Do some logic
  }

Clone this wiki locally