Stats

159 Contributors: 13 Thursday, July 20, 2017
Licensed under: CC-BY-SA
Not affiliated with Stack Overflow
Rip Tutorial: riptutorial@gmail.com
Roadmap: roadmap

Append

Syntax

  1. $(selector).append(content)
  2. $(content).appendTo(selector)

Parameters

ParametersDetails
contentPossible types: Element, HTML string, text, array, object or even a function returning a string.

Remarks

  • .append() & .after() can potentially execute code. This can occur by injection of script tags or use of HTML attributes that execute code (for example, ). Do not use these methods to insert strings obtained from untrusted sources such as URL query parameters, cookies, or form inputs. Doing so can introduce cross-site-scripting (XSS) vulnerabilities. Remove or escape any user input before adding content to the document.

  • jQuery doesn't officially support SVG. Using jQuery methods on SVG
    documents, unless explicitly documented for that method, might cause unexpected behaviors. Examples of methods that support SVG as of
    jQuery 3.0 are addClass and removeClass.

Related Examples